Thursday, November 4, 2010

Turning off the "Identity" column for a table

There are times you may want to temporarily turn off the population of a PK column's use of the identity value. This could be especially useful during data migration.

SET IDENTITY_INSERT tablename ON
SET IDENTITY_INSERT tablename OFF

The ON/OFF is referring to the SQL statement's ability to insert identity column value. When you turn it ON - you're telling the script that you'll provide the identity column value (so it won't)!