DBCC CHECKIDENT RESEED 0

By FoxLearn 12/12/2024 4:15:56 AM   33
The DBCC CHECKIDENT command in SQL Server is used to check the current identity value of a table and, optionally, to reset the seed value of an identity column.

SQL RESEED identity to 0

This will reset the identity seed of the table's identity column to 0.

DBCC CHECKIDENT (table_name, RESEED, 0)

This means that the next time a new row is inserted, the identity column will start at 1 (because the next value is always seed + 1).

If you have a table called Customers with an identity column called CustomerID, and you want to reset the identity column seed to 0.

DBCC CHECKIDENT ('Customers', RESEED, 0)

Output

Checking identity information: current identity value '640'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Completion time: 2024-12-12T11:01:11.4837763+07:00

After this, the next record inserted into the Customers table will have an CustomerID of 1 (if 1 is the next increment based on your identity column's increment value).

If the identity column is using an increment of 1, reseeding to 0 will result in the next insert having the value 1. This will not affect the data in the table; it just resets the counter for the identity column.