SQL Server Reset Identity Increment for all tables

前端 未结 9 1539
面向向阳花
面向向阳花 2021-01-30 05:38

Basically I need to reset Identity Increment for all tables to its original. Here I tried some code, but it fails.

http://pastebin.com/KSyvtK5b

Actual code from

9条回答
  •  无人共我
    2021-01-30 06:22

    Slight tweak on marc_s answer.

    exec sp_MSforeachtable @command1 = 'DBCC CHECKIDENT (''?'', RESEED)'
    

    Those single-quotes around the ? character are important. That statement will cause SQL Server to automatically recalculate the next identity value for each table.

提交回复
热议问题