Naming convention for unique constraint

前端 未结 3 1378
悲哀的现实
悲哀的现实 2021-01-29 18:03

Naming conventions are important, and primary key and foreign key have commonly used and obvious conventions (PK_Table and FK_Table_ReferencedTable, re

3条回答
  •  你的背包
    2021-01-29 18:48

    My thinking is it isn't a key: it's a constraint.

    It could be used as a key of course, and uniquely identifies a row, but it isn't the key.

    An example would be that the key is "ThingID", a surrogate key used in place of ThingName the natural key. You still need to constrain ThingName: it won't be used as a key though.

    I'd also use UQ and UQC (if clustered).

    You could use a unique index instead and go for "IXU". By the logic employed, an index is also a key but only when unique. Otherwise it's an index. So then we'd start with IK_columnname for unique indexes and IX_columnname for non-unique indexes. Marvellous.

    And the only difference between a unique constraint and a unique index is INCLUDE columns.

    Edit: Feb 2013. Since SQL Server 2008, indexes can have filters too. Constraints can not

    So, it comes down to one of

    • stick with UQ as per the rest of the SQL-using planet
    • use IK for unique indexes (IKC for clustered too) to be consistent...

提交回复
热议问题