How to re-start SQL Server auto-increment column from 1

Source: Internet
Author: User
The original ID field of the database is an auto-incrementing column. After all the data is deleted, the ID auto-incrementing column is counted from 1.

Method 1:

1. dbcc checkident ('test', reseed, 0)
2. insert into test values (55)

Select * from test

Display result:

Id msum

1 55

Method 2:

SET IDENTITY_Insert

Explicit values can be inserted into the table's ID column.

Syntax:
SET IDENTITY_Insert [database_name. [schema_name].] table {ON | OFF}
Set identity_insert dbo. test on
Test is the table name.
Note: After you use set identity_insert dbo. test on, when you insert into, you must write the fields that need to be inserted into the record, for example:
Insert into test (id, msum) values (1, 55)
Insert into test (id, msum) values (2, 55)
The statement below is incorrectly written:
Insert into test values (55)
Insert into test values (1, 55)

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.