MySQL sets the starting value of the from-Grow primary key

Source: Internet
Author: User
Tags mysql in


MySQL can use auto_increment to set the value of the primary key is self growth, its default value is 1, if you want to set its initial value to 1000, the more stupid way is to insert a record and specify the primary key value of 999, and then delete the row record, for example:

The code is as follows Copy Code

INSERT into Test (PK) values (999);
Delete from test where PK = 999;

A better approach is to use Alter's method to modify directly, for example:

The code is as follows Copy Code

ALTER TABLE Test auto_increment = 200;

Resets the initial value of the primary key for MySQL in addition to the test data. When you delete a data entry with a self-added property primary key in MySQL, you want to restore the primary Key's self-added initial value to a value the next time you insert the data, you can do this:

The code is as follows Copy Code
ALTER TABLE TableName Auto_increment=1


(Reset initial value to 1)

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.