What is the difference between Unique Key and Index with IsUnique=Yes?

后端 未结 6 1463
别那么骄傲
别那么骄傲 2021-02-04 23:45

I have a table with a primary key, but I want two other columns to be constrained so the combination of the two is guaranteed always to be unique.

(a dumb example: In a

6条回答
  •  不知归路
    2021-02-05 00:27

    One thing I just found out the hard way is that in SSMS scripting of unique keys was set to true by default but the scripting of indices was set to False. When I used the Script Table As context menu from SSMS I didn't get my unique indices.

    Also if the type is set to Unique Key, you can't change the "Ignore Duplicate Key" setting. First you have change the type from Unique Key to Index then you can set Ignore Duplicate Keys to true.

提交回复
热议问题