Posts

Showing posts from August, 2015

SQL Server – T-SQL script for automatic reseeding of all identity tables within a given database

After some back to back problem driven posts, I thought to post something different, which should be equally tricky but more to fun and what’s better than a good T-SQL script. Recently in one of my projects I got a requirement to come up with a T-SQL script which can automatically reseed all tables on any given database if need be. Below is the result of this requirement. I've created a SP which can automatically check for current identity value of all the tables within a given database and can reseed it to new value. The SP takes three parameter viz. Database Name "@db_name (nvarchar(255))" , Print Bit "@print_bit (bit)" , Increment value "@incr_val (int)" . This will reseed the value of identity column of all the tables in a given database with new incremented value provided. The "@incr_val"  defaults to 0, which will reseed the identity column to start with immediate next value in the identity series defined. The "@print-bit&qu