Replace usage in mysql

Source: Internet
Author: User


Replace usage in mysql there are three forms of MySQL replace into: 1. replace into tbl_name (col_name ,...) values (...) 2. replace into tbl_name (col_name ,...) select... 3. replace into tbl_name set col_name = value ,... the first form is similar to insert into. The second replace select method is similar to insert select, which does not necessarily require column name matching. In fact, MYSQL does not even care about the column name returned by select, it requires the column position. For example, replace into tb1 (name, title, mood) select rname, rtitle, rmood from tb2 ;? In this example, replace into is used from? Import all data to tb1 in tb2. The third replace set usage of www.2cto.com is similar to the update set usage, and a value assignment such as "SET col_name = col_name + 1" is used, the reference to the column name on the right is processed as DEFAULT (col_name. Therefore, the value is equivalent to SET col_name = DEFAULT (col_name) + 1. Full usage statement: replace into 'table' ('unique _ column', 'num') VALUES ('$ unique_value', $ num ); insert into 'table' ('unique _ column', 'num') VALUES ('$ unique_value', $ num) on duplicate update num = $ num; in fact, it is the same as other usage.

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.