Quantcast
Channel: HTML element – Random Technical Thoughts
Viewing all articles
Browse latest Browse all 8

How to insert records to a table with an identity column

0
0

If you have a table with an identity column, you can’t just do a simple insert.  That identity column needs to be excluded from your insert statement.

There are times when you need to keep the ID values during your insert.  Like moving data between environments.

Here is the SQL you need to allow your inserts to work.
First turn on identity_insert

SET IDENTITY_INSERT <TABLENAME> ON;

Then do your insert.

Then turn off identity_insert

SET IDENTITY_INSERT <TABLENAME> OFF;
[tweetmeme only_single=”false”]


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images