Tutorialsplane

SQL Prevent Duplicate INSERT – MySql


SQL Prevent Duplicate INSERT – MySql : If you are working with mysql insert operation and want to stop duplicate insertion operation . You can use INSERT IGNORE statement. This will prevent the duplicate row insertion.


SQL Prevent Duplicate INSERT – MySql

Here is an example of Insert ignore statement in mysql

SQL Prevent Duplicate INSERT – MySql

mysql> INSERT IGNORE INTO users (user_id, email) VALUES (32, test@ymail.com);
Query OK, 1 row affected (0.01 sec)

mysql> INSERT IGNORE INTO users (user_id, email) VALUES (32, test@ymail.com);
Query OK, 0 rows affected (0.00 sec)

The above example clearly shows when you run the same query to insert the same data it will not insert the data again.