MySQL primary key self-growing problem

Source: Internet
Author: User
So, the simple MySQL table, the ID is the primary key, and it is growing from.

ID  value1    ok2    Good


Now I delete the above two records, the whole table is an empty table, and then I add a record (directly fill in the value, do not indicate the primary key).

He became:
ID  value3   new


ID starting from 3, the previous ID record was deleted by me, his ID how to start from 3, what is the meaning of this?


Reply to discussion (solution)

If you use the empty command, you will not start from 3.

The self-increment primary key is like this, you truncate table; And then starting from 1.

Clear the table, or reset the Auto_increment

The difference between delete and truncate:
Delete from table name Delete is not returned;
TRUNCATE TABLE name when the table is emptied, the primary key automatically increases the value to the bit.
Landlord if the MySQL database does not understand, you can go to see Hanzhongkang Teacher's MySQL video tutorial!

ID int PRIMARY KEY auto_incrmement autogrow does not delete ID, ID does not automatically return to 0

  • 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.