Home > Database > Mysql Tutorial > body text

Detailed explanation of replace into example of mysql

黄舟
Release: 2017-06-04 09:55:54
Original
1486 people have browsed it

This article mainly introduces the relevant information about the detailed explanation of the replace into instance of mysql. Friends in need can refer to the detailed explanation of the replace into instance of

##mysql

replace into has a similar function to insert. The difference is that replace into first tries to

insert data into the table.

1. If it is found that this row of data already exists in the table (judged based on the primary key or unique

index ), first delete this row of data, and 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, ...
Copy after login

Extension: mysql gets the last part of the corresponding insertion Primary key (general users obtain the primary key order number of the order table)

SELECT LAST_INSERT_ID() from dual
Copy after login

The above is the detailed content of Detailed explanation of replace into example of mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template