When using the following two methods, the field must be set to "primary key" or "UNIQUE constraint (UNIQUE )".
1: Use replace into (This method uses the replacement method, which is a bit similar to deleting and then inserting)
Copy codeThe Code is as follows:
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 highly efficient and can be used to determine whether it exists or not. Otherwise, it will be inserted)
Copy codeThe Code is as follows:
INSERT [IGNORE] INTO Syntax
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name [(col_name,...)]
{VALUES | VALUE} ({expr [...]