Reputation: 111
How can I insert data into a column which has been defined as auto increment column using identity insert?please explain with an example.
Upvotes: 4
Views: 2714
Reputation: 755531
If you have an "auto-increment" column - you really shouldn't be inserted specific values into that column yourself - after all, that's why it's an auto-increment column....
If you must do so after all - then you need to do:
SET IDENTITY_INSERT (your table name here) ON
INSERT INTO (your table name here) (IdentityCol, OtherCol1, .....)
VALUES( (new ID value), .......)
SET IDENTITY_INSERT (your table name here) OFF
Upvotes: 4