Learn DBCC checkident

Source: Internet
Author: User
Source SQL books online

Check the current Identifier value of the specified table. If necessary, correct the Identifier value.

Syntax
DBCC checkident
('Table _ name'
[, {Noreseed
| {Reseed [, new_reseed_value]}
}
]
)

If the primary key or unique key constraint exists in the column,
Use DBCC checkident ('table _ name', reseed, new_reseed_value) to set the current value to new_reseed_value. Note the following when using this parameter:The value of new_reseed_value should take the maximum value in the current ID column to avoid insertion errors.

Example
A. Reset the current ID value if necessary
In the following example, the current identity value of the jobs table is reset if necessary.

Use pubs
Go
DBCC checkident (jobs)
Go

B. report the current ID value
The following example shows the current identity value in the jobs table. If the identity value is incorrect, it is not corrected.

Use pubs
Go
DBCC checkident (jobs, noreseed)
Go

C. Force the current ID value to 30
In the following example, the current ID value of the mandatory jobs table is 30.

Use pubs
Go
DBCC checkident (jobs, reseed, 30)
Go

PS:
In the example of local Experiment C, the current ID has a maximum value of 14. After modification, legal data is inserted and job_id = 31 is added;

If DBCC checkident (jobs, reseed, 30) is executed and data is inserted at this time, an error occurs:
Primary key constraint failure error. Invalid ID information may cause error 2627.

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.