INSERT INTO adds new rows to a table.
Syntax
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
Example — Single Row
INSERT INTO employees (name, department, salary)
VALUES ('Neha', 'Design', 48000);
Example — Multiple Rows in One Statement
INSERT INTO employees (name, department, salary) VALUES
('Aman', 'Engineering', 65000),
('Riya', 'Marketing', 52000),
('Karan', 'Engineering', 71000);
Inserting multiple rows in one statement is significantly faster than running separate INSERT statements one at a time, since it avoids repeated round-trips to the database.
INSERT INTO ... SELECT — Copying Data
INSERT INTO archived_orders
SELECT * FROM orders WHERE order_date < '2023-01-01';
Copies rows from one table's query result directly into another — no need to pull data out and back in through application code.
Common Mistakes
- Column/value order mismatch — values are matched to columns positionally; swapping the order silently puts data in the wrong column if types happen to be compatible
- Omitting a required (NOT NULL, no default) column — causes the insert to fail
- Skipping the column list entirely (
INSERT INTO employees VALUES (...)) — works, but breaks silently if the table's column order ever changes; always name columns explicitly
Interview Relevance
You may be asked to write an INSERT INTO ... SELECT to migrate or archive data — a very common real-world data engineering pattern, not just a syntax exercise.
Practice Question
Write a statement that inserts 3 new students into a students table with columns (name, course) in a single statement.