• Based on the question:

    Is it possible to create a table with unique constraint that allows multiple NULL values from SQL Server 2008 onwards?

    I don't disagree with the correct answer. I disagree with the explanation. I also do disagree with many of the complaints thus far about the question. You can most certainly have multiple null values in a unique constraint. Don't constrain yourselves to a narrow scope of a constraint on a single column - where you can have only one null value.

    Instead expand that constraint a little and the question is completely valid.

    USE tempdb;

    Go

    CREATE TABLE sometest (testid INT, col1 INT, col2 INT);

    ALTER TABLE sometest

    ADD CONSTRAINT someconstraint UNIQUE (testid,col1,col2);

    INSERT INTO sometest(testid,col1,col2)

    VALUES (NULL,1,1),(1,NULL,1),(NULL,NULL,NULL);

    SELECT *

    FROM sometest;

    DROP TABLE sometest;

    This demonstrates that multiple null values is possible and that multiple null values is even possible within each of the columns so long as all of the columns together remain unique.

    That said, the sample code provided in the explanation for this question does work. It does allow two null values to be inserted. And it is also a form of creating a unique constraint.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events