How to insert into the PK column when it is an auto-number

Normally, trying to insert data into an identity column (autoincremental column) results in an error message. However, there are cases when we need to do this, and using SET IDENTITY_INERT, it is possible. Here is how: SET IDENTITY_INSERT MyTable ON INSERT INTO MyTable(MyTableId, …) VALUES (42, …) SET IDENTITY_INSERT MyTable OFF Here is the message […]

READ MORE