The following line resets the Identity value for the Customer table to
0 so that the next record added starts at 1.
Syntax:
DBCC CHECKIDENT('Customer', RESEED, 0)
Showing posts with label DBCC. Show all posts
Showing posts with label DBCC. Show all posts
Thursday, 22 August 2013
Reset Identity column to default in SQL Server
Usage of IDENT_INCR and IDENT_SEED function of Identity column in sql server
Here we are see how to get the Increment & Seed Settings of Indentity in the table. IDENTITY(SEED,INCREMENT)== IDENTITY(10,5) Query Snippet: -- Create table with identity column CREATE TABLE MyOrders2 ( OrderID int IDENTITY(10,5), ProductName varchar(20) ); select IDENT_INCR('MyOrders2') -- 5 select IDENT_SEED ('MyOrders2') -- 10 drop table MyOrders2 -- Create table with identity column CREATE TABLE MyOrders2 ( OrderID int IDENTITY(100,50), ProductName varchar(20) ); select IDENT_INCR('MyOrders2') -- 50 select IDENT_SEED ('MyOrders2') – 100 Try After Reseting the Indentity by the below command: dbcc CHECKIDENT('MyOrders2',RESEED,10) It still shows the original setup in the table not the reset value by “CHECKIDENT” command. select IDENT_INCR('MyOrders2') -- 50 select IDENT_SEED ('MyOrders2') – 100
Subscribe to:
Posts (Atom)