Analysis of replace into statements in mysql

Source: Internet
Author: User

Replace into is very similar to insert into. The only difference is that when replace into is used, the system first checks whether there is a record that is the same as the statement to replace into Based on the table's primary key, if yes, delete the old record and insert a new record. In addition, after the replace into statement is executed, a value is returned. If it is set to 1, a data entry is inserted during execution. If it is set to 2, the old record is deleted and a new record is inserted. Although replace into does not cause any serious problems during normal use. If the table we want to operate on has an auto-increment primary key, a problem arises. First, because the new record and the old record have different primary key values, all the associations established with the old data primary key id in other tables will be damaged. Second, frequent replace into causes the primary key value of the new record to increase rapidly. One day. When the maximum value is reached, the data overflows because of the large amount of data. There is no way to insert new records. The data table is full, not because the space is insufficient, but because the value of the primary key cannot be increased. Author uohzoaix

Related Article

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.