INSERT Record — SQL Technical Interview Questions & Answers

INSERT Record

INSERT Record

  • INSERT INTO students (roll, name, marks) VALUES (12, 'Asha', 72); adds one row. List the columns. Don’t rely on column order in the table — tomorrow someone ALTERs it.
  • Many rows: INSERT INTO students (roll, name, marks) VALUES (12,'Asha',72), (13,'Kabir',40); One statement, two rows.
  • AUTO_INCREMENT: skip that column, MySQL fills it. Duplicate PRIMARY KEY → error 1062. INSERT IGNORE skips the bad row. ON DUPLICATE KEY UPDATE changes the old row instead.
  • Trap: INSERT INTO students VALUES ('Asha', 12, 72) with columns in the wrong order. Trap: inserting NULL into NOT NULL.
  • On the example next to this theory: INSERT Record — iNSERT adds rows. List columns explicitly for clarity.

Technical Interview Tip: INSERT INTO students (roll, name, marks) VALUES (12, 'Asha', 72);

Code Examples for INSERT Record

INSERT Record — 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 Record — iNSERT adds rows. List columns explicitly for clarity.

How to Explain INSERT Record to an Interviewer

Write an INSERT.

INSERT INTO students (roll, name, marks) VALUES (12, 'Asha', 72);

How do you insert two rows?

Two tuples in VALUES (12,'Asha',72), (13,'Kabir',40)