Insert Query In SQL

Galaxy Glossary

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

The INSERT statement is fundamental in SQL for adding new rows of data into a table. It's a crucial part of any database application that needs to manage and update information.
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 statement is used to add new rows to a table in a relational database. It's a core part of the Data Manipulation Language (DML) and allows you to populate your database with fresh data. Understanding how to use INSERT effectively is essential for any SQL developer. This statement specifies the table to insert into and the values for the columns. It's important to ensure the data types match the columns' definitions. For example, you can't insert a string into a numeric column without proper conversion. The INSERT statement can be used in various ways, from inserting a single row to inserting multiple rows at once, depending on your needs. A common use case is adding new customer records to a customer table, or adding product details to a product inventory table.

Why Insert Query In SQL is important

The INSERT statement is crucial for populating databases with data. Without it, you wouldn't be able to add new records, making your database useless. It's a fundamental building block for any application that interacts with a database.

Example Usage


-- Inserting a new customer into the Customers table
INSERT INTO Customers (CustomerID, FirstName, LastName, Email)
VALUES (101, 'John', 'Doe', 'john.doe@example.com');

-- Inserting multiple customers at once using a VALUES clause
INSERT INTO Customers (CustomerID, FirstName, LastName, Email)
VALUES
(102, 'Jane', 'Smith', 'jane.smith@example.com'),
(103, 'Peter', 'Jones', 'peter.jones@example.com');

-- Inserting data from another table (using SELECT)
INSERT INTO Orders (OrderID, CustomerID, OrderDate)
SELECT 201, 101, CURRENT_DATE
FROM Customers
WHERE CustomerID = 101;

Common Mistakes

Want to learn about other SQL terms?