Insert Values to Identity columns.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 258
We can also insert values to our Identity columns.
Suppose we have Employee_Master table which has Employee_Id as Identity columns assigned to it.
So,with the help of IDENTITY_INSERT,we can insert values into Identity columns.It has ON/OFF values .

SET IDENTITY_INSERT Employee_Master ON

INSERT INTO Employee_Master(Employee_Id,Employee_Name,Address) VALUES(3,'Vishal','Noida');
INSERT INTO Employee_Master(Employee_Id,Employee_Name,Address) VALUES(4,'Neeraj','Hyderabad');

SET IDENTITY_INSERT Employee_Master OFF

INSERT INTO Employee_Master(Employee_Name,Address) VALUES('Sapna','Noida');

Note:-After Inserting your own value to identity field don't forget to set IDENTITY_INSERT OFF.

Comments or Responses

Login to post response