Speaking in Code

Wednesday, February 04, 2009

Using Identity Insert

When copying data from one database to another, in a table with an IDENTITY column, you want to keep the values for the IDENTITY column. Set IDENTITY_INSERT ON for the table being inserted into.

SET IDENTITY_INSERT dbo.Client ON
INSERT INTO dbo.CLIENT (ClientID, ClientName) VALUES (782, 'Edgewood Solutions')
INSERT INTO dbo.CLIENT (ClientID, ClientName) VALUES (783, 'Microsoft')
SET IDENTITY_INSERT dbo.Client OFF

0 Comments:

Post a Comment

<< Home