Primary key vs Unique key

  • Comments posted to this topic are about the item Primary key vs Unique key

    rkaram

  • +1

    Vimal LohaniSQL DBA | MCP (70-461,70-462)==============================The greatest barrier to success is the fear of failure ** Success is a journey not a destination**Think before you print, SAVE TREES, Protect Mother Nature

  • Eaaazy, I think there was a similar question b4.

    Have a nice day 🙂

  • Hany Helmy (10/27/2014)


    Eaaazy, I think there was a similar question b4.

    Have a nice day 🙂

    +1

  • "only one null " is someway misleading. Precisley it's a "only one null value per column".

  • Easy question, thanks!

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • serg-52 (10/28/2014)


    "only one null " is someway misleading. Precisley it's a "only one null value per column".

    If the unique index is not a filtered index 😉

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Question that is very often asked on interviews 🙂

    Thanks!

  • Koen Verbeeck (10/28/2014)


    serg-52 (10/28/2014)


    "only one null " is someway misleading. Precisley it's a "only one null value per column".

    If the unique index is not a filtered index 😉

    The question was about a unique "key", which I assume is intended to mean unique "constraint" not "index" (given the context with primary key in the same sentence, and the answer option about defauult index created).

    One NULL is correct for a single-column constraint, not for composite. A better way to phrase it is that a UNIQUE constraint allows NULLs (as per ANSI standard), but treats NULL as a normal value that also has to conform to the uniqueness constraint (in violation of that same standard).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Koen Verbeeck (10/28/2014)


    serg-52 (10/28/2014)


    "only one null " is someway misleading. Precisley it's a "only one null value per column".

    If the unique index is not a filtered index 😉

    It's another point of confusion. SQL has PRIMARY KEY but has no any 'UNIQUE KEY'. We have UNIQUE constraint and UNIQUE INDEX instead. Most probably 'UNIQUE KEY' here is supposed to be UNIQUE constraint which has no WHERE (filtering) option.

  • This was removed by the editor as SPAM

  • very easy question... 😀

    Manik
    You cannot get to the top by sitting on your bottom.

  • I'm glad I wasn't the only one to see "unique key" and think "unique constraint" automatically and then wonder if that was the rub.

  • +1

    Thanks!

    ---------------
    Mel. 😎

  • Good Question, thanks!

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic. Login to reply