Last active
August 29, 2015 13:57
-
-
Save chilversc/9464280 to your computer and use it in GitHub Desktop.
MSSQL 2008 allowing nulls in unique constraints.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- See http://technet.microsoft.com/en-us/library/ms188783.aspx | |
-- "For UNIQUE indexes, only the selected rows must have unique index values." | |
CREATE TABLE foo (pk int PRIMARY KEY IDENTITY, x int NULL); | |
GO | |
CREATE UNIQUE INDEX U_Foo_x ON foo (x) WHERE x is not null; | |
GO | |
INSERT INTO foo (x) VALUES (1); | |
INSERT INTO foo (x) VALUES (2); | |
INSERT INTO foo (x) VALUES (NULL); | |
INSERT INTO foo (x) VALUES (NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment