October 21, 2010 at 12:22 am
Suppose I have a tableA with primary key has Identity column. In this table multiple user inserts the data simulatenously so because of Indetity column it may create Primary key violation error. If I create Intead of insert trigger to check value is unique then it creates performance issue.
I would like to know what is the best way to handle this situation so user does not receive primary key violation & still we are able to insert the data?
Thanks
October 21, 2010 at 1:54 am
In this table multiple user inserts the data simulatenously so because of Indetity column it may create Primary key violation error.
What makes you say this?
Having an identity column as the primary key should not cause duplicates, no matter how many users are simultaneously inserting data into the table.
October 21, 2010 at 4:13 am
Do not Insert data with IDENTITY_INSERT ON option. Then SQL Server take care of concurrency, it is guranteed that there will not be any duplicate id in Identity column.
October 21, 2010 at 4:16 am
I was thinking that due to multiple user is entering the data at same time, it may generate primary key violation.
Thanks
October 21, 2010 at 4:24 am
Be Cool! You can trust on SQL Server Identity column. It will not give you duplicates.
October 21, 2010 at 4:33 am
Not if you let SQL manage the identity column. You may get gaps (due to rollbacks), but not duplicates.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 24, 2010 at 7:29 pm
Hardy21 (10/21/2010)
I was thinking that due to multiple user is entering the data at same time, it may generate primary key violation.
Read up on it in Books Online... you'll feel much better.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply