Using the "IGNORE" keyword prevents errors from occurring. The records containing duplicate primary keys are ignored and the rest of the records are added. In the former case, no record will be inserted if such an error occurs.
The syntax is simple - just add "IGNORE" after "INSERT". Lets see an example:
INSERT IGNORE INTO tablename (id, field1, field2) VALUES (1, 'value1', 'value2');
In the above query, the id is assumed to be the primary key. If a record in the table 'tablename' has already a record with id = 1 then the above query will just be ignored instead of producing a warning. Note: Use the IGNORE keyword only during the development phase. It could cause unexpected results as you cannot identify if the record has been inserted or not.

0 Response to "MySQL - INSERT IGNORE INTO"
Posting Komentar