Tuesday, February 19, 2019

SQL Server - Reset Table Identity Value and Insert

1. DBCC CHECKINDENT RESEED can be used to reset a tables identity value on a column.
Syntax: DBCC CHECKIDENT ('[Table_Name]', RESEED, 0);
This command will reset the identity column value to '0'.2. SET Identity_insert - allow inserting explicit values into the identity column of a table. The IDENTITY_INSERT statement must be set ON to insert explicit value for the identity column.
Syntax: SET IDENTITY_INSERT [dbo].[Table_Name] ON ;
Identity insert should be set to 'OFF' after insertion. To off identity insertion use following command.
Syntax: SET IDENTITY_INSERT [dbo].[Table_Name] OFF ;