当我希望一列具有不同的值时,我可以使用约束
create table t1(
id int primary key,
code varchar(10) unique NULL
);
go
Run Code Online (Sandbox Code Playgroud)
或者我可以使用唯一索引
create table t2(
id int primary key,
code varchar(10) NULL
);
go
create unique index I_t2 on t2(code);
Run Code Online (Sandbox Code Playgroud)
具有唯一约束的列似乎是唯一索引的良好候选者。
是否有任何已知的原因使用唯一约束而不是使用唯一索引?
index sql-server constraint best-practices unique-constraint