In mybatis data table (mysql), the primary key does not grow. how do I insert data (primary key needs to be inserted) to achieve auto growth of the primary key?

Source: Internet
Author: User
For example, there are three fields: Table person, person, id (mysql database, primary key, non-auto-increment), and name and pswd. In the case of auto-increment, we usually process insertintoperson (name, pswd) values (# {name}, # {pswd}) in this way. you are not allowed to insert a primary key, because the primary keys of the person table are auto-incrementing. But what if the primary key does not grow? How to handle it. If the primary key is not auto-incrementing, the primary key must be inserted. When modifying the table structure in a step! I can think of two ways to solve this problem: one is to achieve auto-growth when the primary key is inserted, for example, the first primary key to insert 1,... mysqlmybatis data

For example, there are three fields: Table person, person, id (mysql database, primary key, non-auto-increment), and name and pswd. This is usually the case for auto-increment.

Insert into person (name, pswd) values (# {name}, # {pswd })

In this case, you are not allowed to insert a primary key because the primary key of the person table is auto-incrementing. But what if the primary key does not grow? How to handle it. If the primary key is not auto-incrementing, the primary key must be inserted.
When modifying the table structure in a step! I can think of two ways to solve this problem. one is to achieve auto-growth when the primary key is inserted, for example, the first primary key is inserted into 1 and the second is inserted into 2. this method is not very good. The second is whether mapper. xml can achieve self-growth like the oracle sequence, and the younger brother is not capable enough. I hope you can give me more advice. If you have better methods, please point out.

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.