Is there any concern in referencing a unique index from a foreign key table?
Using SQL Server 2008 R2
foreign keysql-server-2008-r2unique-constraint
Is there any concern in referencing a unique index from a foreign key table?
Using SQL Server 2008 R2
Best Answer
No, a
FOREIGN KEY
constraint can reference a column combination that is either thePRIMARY KEY
or has aUNIQUE
constraint or has aUNIQUE INDEX
.Copied from MSDN page,
CREATE TABLE
:The only difference between the first (primary key) option and the other two is that unique* constraints and indexes can be defined on nullable columns. Primary key columns have to be
NOT NULL
.* Note that there are some slight differences between these in SQL-Server (unique indexes offer some options that are not available with unique constraints): When should I use a unique constraint instead of a unique index?
For example, (as @gbn points), a unique index can be partial. But then, it can't be referenced by a FK.