MySQL conditional data insertion

Source: Internet
Author: User
I have a table with the basic data, and a field is the management number. My goal is to first query the latest management number, generate a new management number according to the rule, and then insert it into the new data in the table.

I have a table with the basic data, and a field is the management number. My goal is to first query the latest management number, generate a new management number according to the rule, and then insert it into the new data in the table.

The requirements are as follows:

I have a table with the basic data, and a field is the management number. My goal is to first query the latest management number, generate a new management number according to the rules, and then insert the new data into the table because the query does not lock the table. so the two threads may find the same management number in the middle of the insert query?

The key is the following MYSQL statement,

Insert multiple records:

  • (Client_id, client_name, client_type)
  • Insert a single record:

  • (Client_id, client_name, client_type)
  • Therefore, you can check that the management number does not exist during insertion. If the insertion is unsuccessful, the latest management number is retrieved and re-calculated before insertion until the insertion is successful.

    There are many such cases, such as tickets for trains and cinemas. Due to the large amount of concurrent processing, tickets with tickets are often found. However, this ticket has been sold when an order is placed, I don't know how these systems are handled.

    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.