Thursday, 21 April 2011

How to Reset Auto Increment ID + SQL Server

USE dbname
GO
DBCC CHECKIDENT (tablename, RESEED, 0)
GO

it will reset to 0 again, but u r col is primary key not continue insert rows because in that col is not support duplicates.


u r column only auto increment then support but duplicates is there.

but u need last all rows is deleted and reset auto increment value assigned exec perfectly.

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. YOU CAN ALSO USE THE FOLLOWING :-
    TRUNCATE TABLE tablename

    By using the above we can also reset our auto increment field and insert data from 1 but it wont work if there is any primary key or foreign key relationship in the respective table.
    Thank you

    ReplyDelete