I have a table with an Identity column as Primary Key.
All is well until one several days ago, application that is using this table start complaining about PK violation. At first I thought this was impossible, until I remember about DBCC CHECKIDENT. The magic function told me that the ‘current column value’ is higher than ‘current identity value’. I RESEED to the highest value and all seemed well again.
My question is, to prevent this from happening again in the future, what are the possible causes of this out of sync problem? And how to prevent it?
It sounds like you would have to search your code to find instances where IDENTITY_INSERT is turned ON, then a (probably high-numbered ident column) key is inserted. Your application has probably gotten lucky in the past in that the inserted (and arbitrary) PK value is within the seed value – probably due to deletions and such.