We perform a table-to-table copy of large data chunks in SQL Compact 3.5. To avoid the problem with identity constraints we use the SET IDENTITY_INSERT table ON before the copying and SET IDENTITY_INSERT table OFF afterwards.
As it is described on MSDN, the identity metainformation, especially the next identity number (AUTOINC_NEXT) is not updated by the SQL Compact runtime while inserting. Therefore after the insert we run into the problems with identity values colliding with inserted values.
We tried the approach recommended on MSDN to increase the identity seed by running the following command:
ALTER TABLE Projects ALTER COLUMN ProjectID IDENTITY (200, 2);
But we get the following error message:
The column cannot become an identity column after it is created.
Is there any way to update the identity seed after the insertion in SQL Compact?
The problem was our false assumption that that the identity column is always the first one in the table. So, the error message came because we tried to make a column as identity which wasn’t actually an identity column before.