Scenario:We have a dbo.Customer table that has ID as identity column. We need to insert one record in this table with -1 for ID.
We will be using Identity_insert ON and Off to do this as shown below.It will disable identity property and then we will insert record and then enable it back.
CREATE TABLE dbo.Customer(
ID INT IDENTITY(1,1) , CustomerCode VARCHAR(50) , FirstName VARCHAR(50) , LastName VARCHAR(50)) SET IDENTITY_INSERT dbo.Customer ON
INSERT INTO dbo.Customer ( ID,CustomerCode,FirstName,LastName)
SET IDENTITY_INSERT Dbo.Customer OFF SELECT * FROM dbo.Customer
|How to insert value in Identity Column manually in SQL Server Table|
Video Demo : How to manually insert the value in identity column in SQL Server Table