Insert Into Table SQL

Galaxy Glossary

How do you add new rows to a table in SQL?

The `INSERT INTO` statement is fundamental to adding new data to a table in a relational database. It specifies the table and the values to be inserted into its columns.
Sign up for the latest in SQL knowledge from the Galaxy Team!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Description

The `INSERT INTO` statement is a crucial part of any SQL developer's toolkit. It allows you to add new records (rows) to an existing table. This is essential for populating your database with data. Understanding how to use `INSERT INTO` correctly is vital for maintaining and updating your database. You can insert data into a table in several ways, depending on the amount of data you need to add and the structure of your table. For example, you might insert a single row, or multiple rows at once. You can also insert data from another table or a query result. The `INSERT INTO` statement is a fundamental building block for data manipulation in SQL.

Why Insert Into Table SQL is important

The `INSERT INTO` statement is essential for populating databases with data. It's a core part of any application that interacts with a database. Without it, you wouldn't be able to add new information to your tables, making the database useless.

Example Usage


-- Inserting a single row
INSERT INTO Customers (CustomerID, FirstName, LastName, City)
VALUES (1, 'John', 'Doe', 'New York');

-- Inserting multiple rows using VALUES clause
INSERT INTO Customers (CustomerID, FirstName, LastName, City)
VALUES
(2, 'Jane', 'Smith', 'Los Angeles'),
(3, 'Peter', 'Jones', 'Chicago');

-- Inserting data from another table (using a SELECT statement)
INSERT INTO Customers (CustomerID, FirstName, LastName, City)
SELECT CustomerID, FirstName, LastName, City FROM TempCustomers;

-- Inserting data with default values for columns
INSERT INTO Orders (OrderID, CustomerID, OrderDate)
VALUES (101, 1, GETDATE());

Common Mistakes

Want to learn about other SQL terms?