Aug 8, 2012

Insert Record in a Table with primary key value

I came across a problem where i deleted on record accidentally and that record id was in use. So I had to Enter that ID in Identity Column and rest of the data in respective fields of that record line. I could add values in other fields but could not enter in Identity Column. So I browsed for the information and this is what I got:

SET IDENTITY_INSERT YourTableName ON

INSERT INTO YourTableName(ID, FirstName, LastName)
VALUES (18, 'Paul', 'Adams')
GO

SET IDENTITY_INSERT YourTableName OFF

No comments:

Post a Comment