Reset identity seed (Identity)
Author: Builder.com
Wednesday, November 3 2004 11:08 AM
Tell the Identity field, there seems to be two very different camps. Some developers, such as those who are respected Joe Celko, believe in the Identity column forgery, introducing meaningless data into one (according to its statement), otherwise it is very compact database. This article is particularly in favor of the second camp (I belong to this camp). This camp believes that an object is almost the same as another object in the same domain (eg, eggs in a basket). We believe that these objects should be given a meaningful primary key (PK). Suppose you rely on the Identity column, which has a specified seed and step into value, then occasionally you need to reset the Identity value. This situation often occurs, because you will delete a lot of row data from the table, and do not want the seed value to reflect millions of test records, but start from 1 (or 10, 100, etc.). But how to reset the seed value after the test? The solution is to run DBCC with the Checkident keyword, specify the appropriate parameters. How to create a lot of data records during the test process, pass the regression test, delete all records, and want to reset the seed to 1, then you just make it simply like the original command: