Methods that ignore duplicate data when sharing MYSQL inserts data
- 2020-06-01 11:08:44
- OfStack
You must set the field to "primary key" (PRIMARY KEY) or "only 1 constraint (UNIQUE)" when using both methods below.
1: use REPLACE INTO (this method makes use of the substitution method, which is similar to the method of first deleting and then inserting)
REPLACE INTO Syntax
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
{VALUES | VALUE} ({expr | DEFAULT}, ... ),( ... ), ...
Or:
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name
SET col_name={expr | DEFAULT}, ...
Or:
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
SELECT ...
2: use INSERT [IGNORE] INTO (this method is more efficient, judge whether it exists, do not insert if there exists, otherwise insert)
INSERT [IGNORE] INTO Syntax
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name [(col_name,...)]
{VALUES | VALUE} ({expr [...]