© copyright 05.Jan.2009 by Paul Bradley filed under Microsoft SQL Server
When I am developing a new system I like to keep my database schema in a separate SQL text file, so I can easily re-create the database while I am testing. I also keep all my test data in a SQL file, so I can easily insert all my test data after recreating a blank copy of the database.
During a demonstrate of the system to the users / clients I find it useful to re-seed the the auto increment values of certain tables before inserting my test data, so that the values used in the demonstration represent realistic values which will be used after the system has been live for several months.
To do this I use the following SQL syntax, where TABLE is replaced with the table name to change, and VALUE is replaced with the new starting value for the identity field.
DBCC CHECKIDENT (TABLE, RESEED, VALUE)
GO
So for example, if I wanted to re-seed the orders table with a starting value of 20,000 - I would use the following SQL syntax.
DBCC CHECKIDENT (ORDERS, RESEED, 20000)
GO
About the Author
Paul Bradley is a VB.NET software developer living and working in Cumbria. He provides PHP & MySQL bespoke development services via his software development company, Carlisle Software Limited.
He has over 20 years programming experience.