replace into is similar to insert in function. The difference is that replace into first tries to insert data into the table. This article mainly introduces the relevant information on the detailed explanation of mysql's replace into example. Friends who need it can refer to it. I hope it can help everyone.
Mysql's replace into example detailed explanation
1. If it is found that this row of data already exists in the table (judged based on the primary key or unique index), delete this row of data first. Then insert new data.
2. Otherwise, insert new data directly.
It should be noted that the table into which data is inserted must have a primary key or a unique index! Otherwise, replace into will insert data directly, which will result in duplicate data in the table.
There are three ways to write replace into in MySQL:
The code is as follows:
replace into table(col, ...) values(...) replace into table(col, ...) select ... replace into table set col=value, ...
Extension: mysql gets the last primary key corresponding to the insertion (general users get the primary key order number of the order table)
##
SELECT LAST_INSERT_ID() from dualRelated recommendations:
Analysis of the difference between REPLACE INTO and INSERT INTO in MySQL
sql replace into usage and implementation statements
REPLACE INTO and INSERT INTO in MySQL Difference analysis_MySQL
The above is the detailed content of Detailed explanation of replace into in mysql. For more information, please follow other related articles on the PHP Chinese website!