duplicate null value violation on UNIQUE KEY constraint in Mssql

前端 未结 1 763
南笙
南笙 2020-12-17 20:28

MS SQL Server does not ignore the null value and considers it as violation for the UNIQUE KEY constraint but what I know is that the UNIQUE KEY differ from the primary key

相关标签:
1条回答
  • 2020-12-17 20:53

    you can create a unique index that ignores null values like this

    CREATE UNIQUE NONCLUSTERED INDEX idx_col1
    ON dbo.MyTable(col1)
    WHERE col1 IS NOT NULL;
    
    0 讨论(0)
提交回复
热议问题