Home >Database >Mysql Tutorial >How can we use MySQL REPLACE statement to prevent duplicate data from being inserted?
#We can use the REPLACE statement when inserting data to prevent inserting duplicate data. If we use REPLACE command instead of INSERT command then if the record is new it will be inserted like INSERT else if it is duplicate the new record will replace the old record. p>
REPLACE INTO table_name(…)
Here, table_name is the name of the table into which we want to insert the value.
In this example, we will insert data with the help of REPLACE statement as follows -
mysql> REPLACE INTO person_tbl (last_name, first_name) -> VALUES( 'Ajay', 'Kumar'); Query OK, 1 row affected (0.00 sec) mysql> REPLACE INTO person_tbl (last_name, first_name) -> VALUES( 'Ajay', 'Kumar'); Query OK, 2 rows affected (0.00 sec)
The above is the detailed content of How can we use MySQL REPLACE statement to prevent duplicate data from being inserted?. For more information, please follow other related articles on the PHP Chinese website!