UNIQUE constraint controlled by a bit column

后端 未结 3 1309
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 05:41

I have a table, something like

FieldsOnForms(
 FieldID int (FK_Fields)
 FormID int (FK_Forms)
 isDeleted bit
)

The pair (FieldID,FormID) s

3条回答
  •  温柔的废话
    2020-12-11 06:22

    You can have a unique index, using the SQL Server 2008 filtered indexes feature, or you can apply a UNIQUE index against a view (poor man's filtered index, works against earlier versions), but you cannot have a UNIQUE constraint such as you've described.

    An example of the filtered index:

     CREATE UNIQUE NONCLUSTERED INDEX IX_FieldsOnForms_NonDeletedUnique ON FieldsOnForms (FieldID,FormID) WHERE isDeleted=0
    

提交回复
热议问题