INSERT IGNORE — SQL Technical Interview Questions & Answers

INSERT IGNORE

INSERT IGNORE

  • INSERT IGNORE INTO students … skips rows that would error (duplicate key, some data issues) and continues. You don’t get a hard fail. Useful for loading a file with a few duplicates.
  • You also won’t notice real problems. Check ROW_COUNT() / warnings. Prefer fixing duplicates over IGNORE in app code.
  • Trap: INSERT IGNORE hiding NOT NULL / type errors you should fix.
  • On the example next to this theory: INSERT IGNORE — iNSERT adds rows. List columns explicitly for clarity.

Technical Interview Tip: INSERT IGNORE skips duplicate-key rows. Don’t hide bugs with it.

Code Examples for INSERT IGNORE

INSERT IGNORE — sample query

CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT, price REAL);
INSERT INTO products (id, name, price) VALUES
  (1, 'Mouse', 499),
  (2, 'Keyboard', 999);
SELECT * FROM products;

INSERT IGNORE — iNSERT adds rows. List columns explicitly for clarity.

How to Explain INSERT IGNORE to an Interviewer

What does INSERT IGNORE do?

Skips rows that would error Does not stop the statement