How to insert a value into an IDENTITY column

By Allen Stoner

IDENTITY columns in MS SQL are often used for generating a unique number for each row in a table. As such they do not, by default, allow you to insert your own value, but sometimes it might be necessary.

set identity_insert TableName on
Insert into TableName (RecordID) values (1345)
set identity_insert TableName off

How to insert a value into an IDENTITY column  (1004 Views)