SQL INSERT INTO
The SQL INSERT INTO statement adds new rows of data into a database table. It is one of the most common operations when working with relational databases, allowing developers to populate tables with meaningful data.
SQL INSERT INTO Syntax
General syntax:
INSERT INTO table_name
VALUES (value1, value2, ...);
Inserting multiple rows:
INSERT INTO table_name
VALUES
(value1, value2, ...),
(value1, value2, ...);
Inserting values into specific columns:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
Inserting default values using the DEFAULT keyword:
INSERT INTO table_name
VALUES (value1, DEFAULT, value3, ...);
Inserting from another table:
INSERT INTO table_name (column1, column2)
SELECT column1, column2
FROM another_table
WHERE condition;
Example 1: Inserting into All Columns Using SQL INSERT INTO
Suppose there is a table named Employees:
| EmployeeID | FirstName | LastName | Department |
|---|---|---|---|
| 1 | John | Doe | HR |
| 2 | Jane | Smith | IT |
This query uses SQL INSERT INTO to insert data into all columns in the Employees table:
INSERT INTO EmployeesVALUES (3, 'Michael', 'Brown', 'Finance');
The output will be:
| EmployeeID | FirstName | LastName | Department |
|---|---|---|---|
| 1 | John | Doe | HR |
| 2 | Jane | Smith | IT |
| 3 | Michael | Brown | Finance |
Example 2: Inserting into Specific Columns Using SQL INSERT INTO
This query uses SQL INSERT INTO to insert data into specific columns in the Employees table:
INSERT INTO Employees (FirstName, LastName)VALUES ('Emily', 'Clark');
The output will be:
| EmployeeID | FirstName | LastName | Department |
|---|---|---|---|
| 1 | John | Doe | HR |
| 2 | Jane | Smith | IT |
| 3 | Michael | Brown | Finance |
| 4 | Emily | Clark | NULL |
Note: The
Departmentcolumn isNULLbecause no value was provided.
Example 3: Inserting Multiple Rows Using SQL INSERT INTO
This query uses SQL INSERT INTO to insert multiple rows of data in the Employees table:
INSERT INTO Employees (FirstName, LastName, Department)VALUES('Chris', 'Evans', 'Marketing'),('Anna', 'Taylor', 'HR'),('David', 'Wilson', 'IT');
The output will be:
| EmployeeID | FirstName | LastName | Department |
|---|---|---|---|
| 1 | John | Doe | HR |
| 2 | Jane | Smith | IT |
| 3 | Michael | Brown | Finance |
| 4 | Emily | Clark | NULL |
| 5 | Chris | Evans | Marketing |
| 6 | Anna | Taylor | HR |
| 7 | David | Wilson | IT |
Frequently Asked Questions
1. How to use SQL INSERT INTO in SQL?
SQL INSERT INTO can be used to add new rows into a table by specifying values for all or selected columns. For example:
INSERT INTO Employees (FirstName, LastName, Department)VALUES ('Alice', 'Johnson', 'Sales');
2. What is the purpose of SQL INSERT INTO?
The purpose of SQL INSERT INTO is to populate a database table with new records. It allows data entry during the initial creation of a database and also for ongoing updates when new information needs to be stored.
3. What is the difference between INSERT and INSERT INTO in SQL?
There is no functional difference between INSERT and INSERT INTO — both are valid SQL syntax for adding new rows to a table. INSERT INTO is the more explicit and commonly used form, supported by all major SQL databases. Some SQL dialects allow the shorter INSERT form, but it is less common.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Learn to analyze data with SQL and prepare for technical interviews.
- Includes 9 Courses
- With Certificate
- Beginner Friendly.18 hours
- In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
- Beginner Friendly.5 hours