SQL can I have a “conditionally unique” constraint on a table?

后端 未结 5 734
时光说笑
时光说笑 2020-12-17 18:03

I\'ve had this come up a couple times in my career, and none of my local peers seems to be able to answer it. Say I have a table that has a \"Description\" field which is a

5条回答
  •  [愿得一人]
    2020-12-17 18:19

    If you are using SQL Server 2008 a Index filter would maybe your solution:

    http://msdn.microsoft.com/en-us/library/ms188783.aspx

    This is how I enforce a Unique Index with multiple NULL values

    CREATE UNIQUE INDEX [IDX_Blah] ON [tblBlah] ([MyCol]) WHERE [MyCol] IS NOT NULL
    

提交回复
热议问题