Resetting the seed of SQL Server self-growing columns

Source: Internet
Author: User

Resetting the seed of SQL Server self-growing columns

Transferred from: http://hi.baidu.com/zbphot/item/41c55982c2d02dd05e0ec184

If the data in the table is not available, use the following statement: TRUNCATE TABLE

If the statement in the table is also, use the following statement: DBCC checkident (table name, reseed, 1)

DBCC checkident (' table_name ', noreseed) does not reset the current identity value.

DBCC Checkident Returns a report that indicates the current identity value and the expected identity value.

DBCC CHECKIDENT (' table_name ') or DBCC CHECKIDENT (' table_name ', reseed) if the current identity value of the table is less than the maximum identity value stored in the column, it is reset with the maximum value in the identity column.

The current value of DBCC checkident (' table_name ', reseed, New_reseed_value) is set to New_reseed_value. If a row has not been inserted into the table since the table was created, the first row inserted after the DBCC checkident is executed uses new_reseed_value as the identity. Otherwise, the next inserted row will use New_reseed_value + 1. If the value of new_reseed_value is less than the maximum value in the identity column, a No. 2627-number error message is generated later when the table is referenced.

If the statement in the table is also, use the following statement:

DBCC checkident (table name, reseed, 1)

DBCC checkident (' table_name ', noreseed) does not reset the current identity value.

DBCC Checkident Returns a report that indicates the current identity value and the expected identity value.

dbcc checkident  (' table_name ') or dbcc checkident  (' table_name ',  reseed)   If the current identity value of the table is less than the maximum identity value stored in the column, it is reset with the maximum value in the identity column.   dbcc checkident  (' table_name ',  reseed, new_reseed_value)   Current value set to  new_reseed _value, the general New_reseed_value is the current largest ID value. If a row has not been inserted into the table since the table was created, the first row inserted after execution   dbcc checkident  uses  new_reseed_value  as the identity. Otherwise, the next inserted row will use  new_reseed_value + 1. If the value of  new_reseed_value  is less than the maximum value in the identity column, subsequent references to the table will result in an error in the   primary key violation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.