This topic describes the syntax for the INSERT statement in Transact-SQL (T-SQL).
The INSERT statement is used to add one or more rows to a table in a SQL Server database.
INSERT [ TOP ( expression ) [ PERCENT ] ] [ INTO ] { object_name } [ ( column_list ) ] VALUES ( value_list ) [ ; ]
INSERT [ TOP ( expression ) [ PERCENT ] ] [ INTO ] { object_name } [ ( column_list ) ] { <;SELECT statement>; } [ ; ]
INSERT [ INTO ] { object_name } [ ( column_list ) ] <;SELECT statement>; [ ; ]
INSERT ( column_list ) <;EXECUTE | EXEC> { stored_procedure_name [ arguments ] } [ ; ]
| Parameter | Description |
|---|---|
TOP ( expression ) [ PERCENT ] |
Optional. Specifies that only a certain number or percentage of rows satisfying the query are inserted. This is typically used with SELECT statements to limit the number of rows being inserted. |
INTO |
Optional keyword. |
object_name |
The name of the table or view into which rows are inserted. |
column_list |
A comma-separated list of columns in the specified table or view into which values are inserted. If omitted, the values in the value_list must be in the same order as the columns in the table definition. |
VALUES ( value_list ) |
Specifies the values to be inserted. The number and data types of the values must match the number and data types of the specified columns. |
value_list |
A comma-separated list of literal values, variables, or expressions to be inserted into the corresponding columns. |
SELECT statement |
A standard SELECT statement that returns the rows to be inserted. The number and data types of the columns in the SELECT list must match the number and data types of the columns in the INSERT INTO clause or the table definition. |
EXECUTE | EXEC |
Executes a stored procedure or extended stored procedure. |
stored_procedure_name |
The name of the stored procedure to execute. |
arguments |
Optional. One or more arguments passed to the stored procedure. |
INSERT INTO Customers (CustomerID, CompanyName, ContactName)
VALUES (101, 'New Corp', 'Jane Doe');
-- Assuming the table has columns: CustomerID, CompanyName, ContactName, City
INSERT INTO Customers
VALUES (102, 'Tech Solutions', 'John Smith', 'New York');
INSERT INTO ArchivedCustomers (CustomerID, CompanyName)
SELECT CustomerID, CompanyName
FROM Customers
WHERE LastPurchaseDate < '2023-01-01';
INSERT INTO ProductSales (ProductID, SaleAmount)
EXEC GetRecentSales;