INSERT Statements

Overview

The INSERT statement adds new rows of data to a table. It can specify values for specific columns or insert the results of a query.

Syntax

INSERT INTO table_name (column1, column2, …)
VALUES (value1, value2, …);

-- Or insert from a SELECT query
INSERT INTO table_name (column1, column2, …)
SELECT column1, column2, …
FROM other_table
WHERE condition;

Examples

1. Basic Insert

INSERT INTO Employees (FirstName, LastName, HireDate)
VALUES ('John', 'Doe', '2024-01-15');

2. Insert Multiple Rows

INSERT INTO Products (ProductName, Price)
VALUES 
  ('Laptop', 1299.99),
  ('Mouse', 19.99),
  ('Keyboard', 49.99);

3. Insert From SELECT

INSERT INTO ArchiveOrders (OrderID, CustomerID, OrderDate)
SELECT OrderID, CustomerID, OrderDate
FROM Orders
WHERE OrderDate < '2023-01-01';

Interactive Demo

See Also