SQL Server reset indetity start value

Source: Internet
Author: User

@ @IDENTITY and scope_identity return at in the current session The last identity value that is generated within any of the tables. However, scope_identity only returns the value inserted into the current scope, and the @ @IDENTITY is not restricted to a specific scope. It is recommended to use @ @identity sparingly.

Ident_current is not subject to scope and session restrictions, but is limited to the specified table . Ident_current can return identity values generated for a particular table in any session and in any scope.

DBCC checkindnt can view the current identity value of the specified table and can use it to reset the value of indentity

The following is the usage of DBCC CHECKIDENT.

DBCC checkident (TableName [, Reseed | Noreseed] [, value])

View the current value for identity (self-increment) in a table: DBCC CHECKIDENT (TABLENAME) or DBCC CHECKINDET (tablename,noreseed)

Resets the identity (self-increment column) of a table to the current value of VALUE:DBCC checkident (TableName, reseed, value)

For example, to change the current value of the self-increment column in the test table to 1, you can use the following command

DBCC checkident (test, reseed,1)

SQL Server reset indetity start value

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.