SQL Insert Into
The INSERT INTO statement adds new rows of data into a table.
Adding new rows with INSERT INTO
Once a table exists, you fill it with data by inserting rows. The INSERT INTO statement is the standard way to write brand-new records into a table. Each statement can add one row or many rows at a time, and you control exactly which columns receive values.
There are two common ways to write the statement. In the first, you list the target columns and then supply a matching set of values. In the second, you skip the column list and provide a value for every column in the table, in the order the columns were defined.
The two syntax forms
-- Form 1: name the columns you are filling
INSERT INTO Employees (first_name, last_name, department, salary)
VALUES ('Amara', 'Okafor', 'Engineering', 72000);
-- Form 2: supply a value for every column, in table order
INSERT INTO Employees
VALUES (101, 'Amara', 'Okafor', 'Engineering', 72000, '2026-03-01');Inserting several rows at once
Most databases let you add multiple rows in a single statement by separating each set of values with a comma. This is faster than sending many separate statements because the database processes them together.
A multi-row insert
INSERT INTO Employees (first_name, last_name, department, salary)
VALUES
('Liam', 'Chen', 'Sales', 58000),
('Priya', 'Nair', 'Marketing', 61000),
('Diego', 'Santos', 'Engineering', 69000);How columns and values line up
The order of the values must match the order of the columns you listed. The first value fills the first column, the second value fills the second column, and so on. If a column is left out of your column list, the database fills it with its default value, an auto-generated number, or NULL, depending on how the table was defined.
- List the columns you are filling so your statement survives future table changes.
- Keep values in the same order as the columns.
- Quote text and dates; leave numbers unquoted.
- Insert many rows in one statement when you have a batch of data to load.
Exercise: SQL Insert Into
What is the purpose of the INSERT INTO statement?