Friday, February 18, 2011

How to re-insert deleted records when there is an identity field

My customers like to delete important records and then have me restore them from a backup when they realize their mistake.

When the column has an identity field, and you want to restore the records with the same number as they had before deleted, you must turn on identity insert with this TSql command

SET IDENTITY_INSERT {YourTableName} ON 

insert the deleted records

SET IDENTITY_INSERT {YourTableName} OFF 

1 comment:

  1. Thanks for sharing this. I need to do this on a live database. Can you tell me how this effects other operations like INSERT AND UPDATE in my table?

    ReplyDelete