SQL self-Increment 0 method

Source: Internet
Author: User
SQL identity Self-increment 0 method
1. Use the DBCC CONSOLE command:
DBCC CHECKIDENT (table name, reseed,0)

2.truncate table can also clear the current identity value
However, when there are constraints such as foreign keys, the table cannot be truncate

You can disable the FOREIGN KEY constraint to truncate the table first:
--Disable FOREIGN KEY constraints
EXEC sp_msforeachtable ' ALTER TABLE? Nocheck constraint All '
--Erase data
TRUNCATE TABLE name
--Enable FOREIGN KEY constraints
EXEC sp_msforeachtable ' ALTER TABLE? Check constraint all '



TRUNCATE TABLE Schedule
TRUNCATE TABLE student Tables
TRUNCATE TABLE Selection Timetable

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.