开发者

How To Correct A Unique Key To Not Allow Duplicate Entries

开发者 https://www.devze.com 2022-12-22 09:15 出处:网络
Here is my problem: The Key \"idx_SR_u_Identity_FingerPrintProfile\" is meant to constrain the fields \"c_r_Fingerprint\" and \"c_r_Profile\" to be unique.

Here is my problem: The Key "idx_SR_u_Identity_FingerPrintProfile" is meant to constrain the fields "c_r_Fingerprint" and "c_r_Profile" to be unique.

It seems that I have done something wrong because all 4 entries in the table have identical values for those two fields. It is okay if two records have the same Fingerprint OR the same Profile, but not BOTH.

How can I correctly specify 开发者_Go百科this unique key, so that such duplicates are not allowed?

How To Correct A Unique Key To Not Allow Duplicate Entries

(source: Rigel222.Com)


I think your key is correct, but MySQL does not apply it to NULL values. The MySQL Docs for CREATE TABLE state:

a UNIQUE index allows multiple NULL values for columns that can contain NULL.

While entries like (1,2) can occur only once, entries like (1,NULL) can occur several times, they are not considered to be duplicates because of the NULL.

Dependent on your use case, you may forbid NULL for the two columns to circumvent the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消