INSERT INTO
Published Jun 26, 2021Updated Jul 13, 2022
Contribute to Docs
The INSERT INTO
command creates and places new rows into a table.
Syntax
INSERT INTO table_name
VALUES (value1, value2, ...);
Multiple rows can be inserted by adding additional sets to the VALUES
clause:
INSERT INTO table_name
VALUES
(value1, value2, ...),
(value1, value2, ...);
To add values corresponding to only specific columns, thereby leaving the rest of the row as default values, specify them alongside the table name:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
Default values can also be added using the DEFAULT
keyword for the relevant column value:
INSERT INTO table_name
VALUES (value1, DEFAULT, value3, ...);
Example
The given query adds a new student to a students
table, providing values for first_name
, last_name
, and enrollment_date
, thereby inserting default values for all other columns:
INSERT INTO students (first_name, last_name, enrollment_date)VALUES ('Jeremy', 'Barbosa', '2016-09-01');
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
- Skill path
Analyze Data with SQL
Learn to analyze data with SQL and prepare for technical interviews.Includes 9 CoursesWith CertificateBeginner Friendly17 hours - Skill path
Design Databases With PostgreSQL
Learn how to query SQL databases and design relational databases to efficiently store large quantities of data.Includes 5 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly5 hours