SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Duplicate value in Identity column


Duplicate value in Identity column

Author
Message
SanjayAttray
SanjayAttray
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5621 Visits: 1619
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.
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59867 Visits: 13297
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.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Rose Bud
Rose Bud
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1773 Visits: 1062
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
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64287 Visits: 18570
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

OCTom
OCTom
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4067 Visits: 4152
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.
Hugo Kornelis
Hugo Kornelis
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18371 Visits: 12426
OCTom (8/16/2010)
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.

I don't see that happening. It could potentially break existing code that relies on identity values not being unique (why? don't ask me - people do the craziest things in SQL Server). And if MS would ban every option that you can use to shoot yourself in the foot, there wouldn't be a lot left...


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
VM-723206
VM-723206
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1010 Visits: 267
Nice question.
SteveBell
SteveBell
Mr or Mrs. 500
Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)

Group: General Forum Members
Points: 552 Visits: 1537
Yep,
I got this one wrong also.

However, it begs the question, "why would you want an identity column in the first place if you intend to insert a duplicate value?"
AppSup_dba
AppSup_dba
Mr or Mrs. 500
Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)

Group: General Forum Members
Points: 562 Visits: 716
In one scenario we had to copy some data from live DB to test DB. Since the table was having an identity column we were not able to make the data consistent hence we used the above mentioned feature...
w00t

Cheers
daniel.noble
daniel.noble
SSC-Addicted
SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)

Group: General Forum Members
Points: 462 Visits: 111
dbowlin (8/16/2010)
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.


I move data from a Live table (with an identity on the PKey) into an Archive table. Just occasionally I need to move a row back into the Live table. Identity insert allows me to move it back with its original ID, thus maintaining references to this row from other tables. So there's one use for it.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search