Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想确保在所有包含“其他”条目的查找表上,PK (Id) 为-1。我有许多仅在选择“其他”时才激活的业务规则,因此至少对于第一次迭代来说,所有“其他”条目都有一个相同的 ID,我可以在规则中使用而不必总是执行规则时查找“其他”的 ID。
您可以添加检查约束,但当然,您必须记住为每个表添加它
CREATE TABLE Lookup ( LookupID int not null primary key, Name varchar(20) not null unique, constraint CK_Lookup_Other CHECK ( (Name='Other' and LookupID=-1) or (Name!='Other' and LookupID!=-1) ) )