The proper way to implement unique constraint that allows multiple NULL values in SQL Server

前端 未结 3 1920
臣服心动
臣服心动 2020-12-17 19:52


I need 1 column in the table to hold unique non-null values or NULL. TSQL UNIQUE constraint treats 2 NULLs as equal, so I cannot

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 20:55

    4 ways:

    • Filtered index (SQL Server 2008) <- recommended based on your tags
    • Trigger (mentioned)
    • Indexed view (in your question)
    • Unique constraint/index with computed column (in your question)

提交回复
热议问题