In this post , I am going to show you that how you can insert values into Identity column.
To insert the values into Identity column, you have need to turn on the IDENTITY_INSERT option.
To illustrate it, Lets create a new table that has an Identity column.
–Creating Table with Identity Column
Create Table MyTestTable ( ID int Identity(1,1), Name varchar(50) )
Now try to insert the data into above created table.
--Insert data into table Insert into MyTestTable(ID,Name) values(1,'Manish')
Executing the above code, you will get the following error message.
SET IDENTITY_INSERT dbo.MyTestTable ON; Insert into MyTestTable(ID,Name) values(1,'Manish') SET IDENTITY_INSERT dbo.MyTestTable OFF;
Now execute the above code, you will get the success message.