Search

Tuesday, December 20, 2011

Inserting data in SQL table with identity


To insert identity values in a table there is a function IDENTITY_INSERT that needs to be set on a table before Insert statement is executed.

Example:
SET IDENTITY_INSERT Table1 ON

INSERT INTO Table1
(Id, firstname, lastname)
(SELECT Id, firstname, lastname
FROM Table2)

SET IDENTITY_INSERT Table1 OFF

No comments:

Post a Comment