MSSQLCity.Com - All about MS SQL
     
About Us  
SSWUG Articles  
Articles  
FAQ  
Administration  
Backup/Restore  
Connectivity  
Development  
General  
Installation  
OLAP  
Replication  
Transfer/move  
Trouble  
SQL 6.5  
Scripts  
Tips  
Test Exams  
Advertise  
Download  
History  
Search  
Traffic  
Related Links  
     
Your button logo
Add to Favorites
 
     
 


I have duplicate identity value error. What can I do?

Answer:

You can run DBCC CHECKIDENT to correct this error. This error sometimes occurs when you insert new rows.

This is the description of DBCC CHECKIDENT from the SQL Server 6.5 BOL:

DBCC CHECKIDENT [(table_name)]
Checks the current identity value and compares it with the maximum value
in the identity column. If the current identity value is invalid, it will
be reset using the maximum value in the identity column. Invalid identity
information can cause SQL Server message 2627 when a PRIMARY KEY or UNIQUE
KEY constraint exists on an identity column.
You can make stored procedure, which will check the identity field and make this sp as sturtup (by using the sp_makestartup stored procedure). This is the test example:

use master
go

CREATE PROCEDURE sp_checkident AS
EXEC ('use pubs
       DBCC CHECKIDENT (jobs)')
go

sp_makestartup sp_checkident
go
Try to create an alert on error 2626 also.


 

 
Visit The SQL Server Worldwide User's Group for all the latest news and information about SQL Server, Oracle, DB2 and XML for developers and administrators.

(c) 1997, 2005 Bits on the Wire, Inc