SQL INSERT
Statement
Learn how to add new rows to database tables using the INSERT statement: the fundamental command for writing data in SQL.
What Is INSERT?
The INSERT statement is one of SQL's four core data manipulation commands. It lets you add new rows of data to an existing table in your database. Every time a user signs up, a purchase is made, or a score is recorded, an INSERT is happening behind the scenes.
The Four DML Commands
Anatomy of a Table
A table has columns (the schema: id, name, grade, email) and rows (actual data). INSERT adds a new row at the bottom.
The Basic Syntax
INSERT With All Columns
Explicit vs Implicit Column Lists
| Explicit Columns | Implicit (No Columns) | |
|---|---|---|
| Syntax | INSERT INTO t (a, b) VALUES (...) | INSERT INTO t VALUES (...) |
| Order matters? | Matches your list | Must match table definition |
| Partial insert? | ✓ Yes | ✕ No |
| Resilient to schema changes? | ✓ Yes | ✕ No |
| Readability | Clear intent | Ambiguous |
Inserting Partial Data
You don't always have values for every column. Columns you skip will receive their default value (often NULL). This only works with an explicit column list.
Inserting Multiple Rows
You can insert several rows in a single statement by separating each set of values with a comma. This is faster than running multiple individual INSERT statements.
How to Write an INSERT
Example 1: Simple Insert
Add a new book to a books table with columns: title, author, and year.
Example 2: Multi-Row Insert
Add three new products to an inventory table with columns: product_name, price, quantity.
Example 3: NULL and DEFAULT
An employees table has: id (auto-increment), name, department, hire_date (defaults to today).
Data Types Matter
Common Mistakes
INSERT Cheat Sheet
| Pattern | Syntax | Use When |
|---|---|---|
| Single row, all cols | INSERT INTO t (a,b) VALUES (1,2); | Adding one complete record |
| Single row, partial | INSERT INTO t (a) VALUES (1); | Some columns have defaults |
| Multiple rows | INSERT INTO t (a,b) VALUES (1,2),(3,4); | Batch loading data |
| With NULL | INSERT INTO t (a,b) VALUES (1, NULL); | Value is unknown or optional |
Question 1 of 5
Which keyword pair begins every INSERT statement?
Question 2 of 5
What is wrong with this statement?
INSERT INTO books (title, year) VALUES ('Dune', '1965');
Question 3 of 5
You want to insert a row but leave the email column empty. The column allows NULL. Which is correct?
Question 4 of 5
How do you insert three rows in a single INSERT statement?
Question 5 of 5
Why is it best practice to always include the column list in an INSERT statement?