Web Software Architecture and Engineering – Life on the Bleeding Edge

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)'


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

  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.

  3. hi, does it apply the foreign key/primary key constraints when doing this ?
    for example, if i import users with PK seed starting at 1000 that are linked to another table using this PK, will that sp udpate the other table to set the right foreign key ?

  4. Great, Saved my Time

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: