method for inserting data when there are self-growing primary keys in the table

Source: Internet
Author: User

How do we insert data in a database table that has its own growth primary key (as shown in the picture)?

Mode one:

When there is less data to insert, that is, we can specify the value of the column (ID) with a single insert, but the newly inserted value cannot be duplicated with the existing value, and must be greater than the maximum value


Mode two:

When the amount of data that needs to be inserted is large, it is obvious that method one is not feasible when it is necessary to bulk generate data inserts by means of stored procedures or other means. So what should we do now?

There are two ways to fix this:

1 The value of this column (ID) can be set to null or 0, so that MySQL will do its own processing


2 Manually specify the column you want to insert, but do not specify the column (ID)


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.