ppmb
asked on
Primary Key Violation
I have a table with Identity(1,1) as Primary Key and been using this table for some months now. All of a sudden, I got the following error message from my app (VB5) saying that there's a primary key violation :
"[Microsoft][ODBC SQL Server Driver][SQL Driver] Violation of PRIMARY KEY constraint 'PK_Staff_Work_Hours_2__78 '. Attempt to insert duplicate key in object 'Staff_Work_Hours' (#2627) [Microsoft][ODBC SQL Server Driver][SQL Server] Command has been aborted. (#2721) "
How did that happen?? What is the cause of it?? and how can I fix it???
"[Microsoft][ODBC SQL Server Driver][SQL Driver] Violation of PRIMARY KEY constraint 'PK_Staff_Work_Hours_2__78
How did that happen?? What is the cause of it?? and how can I fix it???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Forgot to ask you this:
Does dbcc automatically fix the error existed in the identity column???
Thanks!
Does dbcc automatically fix the error existed in the identity column???
Thanks!
No, this will not fix an error. The proposed answer does not solve your problem, and you may feel free to reject it.
This is a very well-known problem, and it cannot be solved with DBCC, because it doesn't cause logical corruption of table structure.
We had this problem a big way, and developed a workaround against it.
This is a very well-known problem, and it cannot be solved with DBCC, because it doesn't cause logical corruption of table structure.
We had this problem a big way, and developed a workaround against it.
Actually, you MIGHT fix it with DBCC checkident once, but it will surely re-appear some time later. So, if you only care about just fixing it once, by all means, you should accept lmorris's answer, because it probably will solve the problem once, but it fixes only the consequence, not the cause.
ASKER
So ,mitek, what suggestion do you have if I insist in using Identity as Primary Key?
ASKER