How do I override the identity column in MSSQL? I tried :
SET IDENTITY_INSERT GeoCountry ON
UPDATE GeoCountry SET CountryID = 18 WHERE CountryID = 250
But I get back a
Line 2: Cannot update identity column ‘CountryID’.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are trying to perform an update, not inserting new rows.
In order to do that, you will need to set
identity_insertON and copy the row you want to update to a new row with the new ID value, then delete the old row (assuming no FK is referencing it)Something along the lines of:
[Given that you are trying to update it, that would suggest it is still in use (i.e. by referencing FK’s) and that makes things more complicated…]