Ignoring Insert Errors

In the MySQL sql language, the insert modifier ignore can sometimes come in handy if you’re wanting to run the query but not worry about errors in your code. In this example below, if the id column is a primary key and a row with 45 already exists, this statement would error without the ignore modifier. Instead, the statement fails silently and any coding you do won’t toss an error.

insert ignore into test (id, car_name) values (45, 'mazda');

Leave a Reply

Your email address will not be published. Required fields are marked *