SQLite3 UNIQUE constraint failed error

You get a UNIQUE constraint failed error when the data that you are inserting has an entry which is already in the corresponding column of the table that you are inserting into.

If you want SQL to IGNORE that error and continue adding other records , then do this :


INSERT or IGNORE into tablename VALUES (value1,value2 , so on );

If you want to replace the values in the table whenever the entry already exists , then do this:


INSERT or REPLACE into tablename VALUES (value1,value2 , so on );

This saves lot of processing on your part and quite useful.

Leave a Comment