Inserting into Identity column
There are times when we need to insert values in SQL Identity column. SQL Server does not allow us implicitly to insert value into Identity columns. But SQL Server allows us to do so explicitly. For example if you have a table named Employees with EmpID column as identity column, and you want to insert values into it, you have to execute the following command before the insert command.
SET IDENTITY_INSERT Employees ON
Alter this command you can insert values into the identity column using insert command.
Once you are finished with insert commands you have to switch Identity off with the following command.
SET IDENTITY_INSERT Employees OFF
Note: The important thing to keep in mind here is that at any given point of time in one session there can be only one table which can have identity ON
Reseeding the identity column value:
You can reseed the indentity column value, that meand you can restart or start at a new predefined value by using DBCC CHECKIDENT. For example, if you have a table named Employees and you want to reseed the indentity column to 1 I would execute the following:
DBCC CHECLIDENT (Employees, reseed, 0)
Here u must have noticed that the to set the value to 1 I have set the value to 0.