how to Reset AutoIncrement in SQL Server after all data Deleted

£可爱£侵袭症+ 提交于 2019-12-02 06:34:34

TRUNCATE TABLE

Removes all rows from a table or specified partitions of a table, without logging the individual row deletions. TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses fewer system and transaction log resources.

TRUNCATE TABLE Customers

or remove your in build function.

Truncate Table Command is good way to reset Identity, but there is other command also to reset Identity after deletion of records.

DBCC CHECKIDENT (TableName, RESEED, 0)

After Deleting you can use this command to reset Identity to 0.

My suggestion is instead of deleting all rows of data why dont you truncate the table.

If you are truncate the table it automatically reset your auto increment to 0

TRUNCATE TABLE your_table_name;

This example would truncate the table and remove all records from that table. and rest your auto increment too.

The SQL TRUNCATE TABLE command is used to delete complete data from an existing table

Try this way. May help you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!