Mysql replace into instance details
Mysql replace into instance details
Replace into is similar to insert. The difference is that replace into first tries to insert data into the table. Mysql replace into instance details
1. If this row of data is found in the table (determined based on the primary key or unique index), delete the row of data and insert new data.
2. Otherwise, insert new data directly.
Note that the table to which data is inserted must have a primary key or a unique index! Otherwise, replace into inserts data directly, which leads to duplicate data in the table.
In MySQL, replace into can be written in three ways:
The Code is as follows:
Replace into table (col,...) values (...)
Replace into table (col,...) select...
Replace into table set col = value ,...
Extension: mysql obtains the last primary key corresponding to the insert (generally, the user obtains the primary key Order Number of the Order table)
SELECT LAST_INSERT_ID () from dual