Web Software Architecture and Engineering – Life on the Bleeding Edge

SQL Server Trick: Script to Reseed All Tables

Sometimes, IDENTITY seeds get messed up, especially after a db restore, so this script comes in handy. It even gives a little report on what the previous value was and what the new values is. For tables that don’t have IDENTITY values, it gives a clean error and skips them. Nice and easy.

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

Advertisement

Comments on: "SQL Server Trick: Script to Reseed All Tables" (2)

  1. Homero Couto said:

    Thank you very much for this script. Saved me a lot of scripting..

  2. Thank you, first result from Google and the nÂș 1 solution.

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 144 other followers