Duplicate value in Identity column

  • Comments posted to this topic are about the item Duplicate value in Identity column

    Cheers

  • hi,

    I know that we can add explicit values to an identity column using

    Identity_Insert on. but i thought that identify column will not allow duplicate columns.good question.lost one point but learned one new point.

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

  • good one... duplicates can only be avoided by having a constraint in place...

  • Nice question. Usually an Identity column is used as a primary key (and thus having a unique clustered index), which will prevent the insertion of duplicate values.

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

  • ziangij (8/15/2010)


    good one... duplicates can only be avoided by having a constraint in place...

    ...or by having a unique index in place.

    Best Regards,

    Chris Büttner

  • And i thought i only didnt knew it 🙂

    Cheers

  • Good Question...

    Thanks
    Vinay Kumar
    -----------------------------------------------------------------
    Keep Learning - Keep Growing !!!

  • I have to admint I wouldn't have gotten this one right, except for a similar question a few months ago. I still don't understand why one would want to create an identity and then break the rules of the identity. Seems like trouble 🙂

  • Identity insert can be very dangerous. For a long time I couldn't see a use for it. Then I needed it to get 2 tables in 2 different databases into sync after they had fallen out of sync for some unknown reason. It saved me a lot of effort.

  • Only one person can insert identity on a column at a time, so WE can not... :hehe:

  • Yes you can insert but should be avoided by having a unique constraint or Pkey on identity column.

    Since, it doesn't make much sense, if you want to put duplicate value in identity column then why add identity option to column int. Just leave it as is.

    SQL DBA.

  • SanjayAttray (8/16/2010)


    Since, it doesn't make much sense, if you want to put duplicate value in identity column then why add identity option to column int. Just leave it as is.

    I think the idea behind this question is to warn people that just using IDENTITY is not enough. Not everybody knows that duplicate entries can still happen with an IDENTITY, so that is a valuable lesson learned with this question.

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

  • Interesting. Very surprised to learn you can enter duplicate values when inserting explicit values.

    Further surprised to learn that you can get duplicate values by resetting the identity seed, according to this person:

    http://beyondrelational.com/blogs/jacob/archive/2009/02/03/sql-server-identity-why-do-i-have-duplicate-identity-values.aspx

  • Nice question.

    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

  • SanjayAttray (8/16/2010)


    Yes you can insert but should be avoided by having a unique constraint or Pkey on identity column.

    Since, it doesn't make much sense, if you want to put duplicate value in identity column then why add identity option to column int. Just leave it as is.

    Perhaps Microsoft should change it so that a PK or unique constraint must accompany an identity column? Like you say, it doesn't make sense to have it this way and is a potential problem.

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

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