INSERT

INSERT#

Adds one or more new rows to a table or view.

Syntax#

insert ::=

INSERT topClausetopClause INTO table ( columnList ) VALUES ( expression list ) , DEFAULT VALUES selectStatementselectStatement executeStatement compatibility only - not executed

Click an element in the diagram to drill down to its definition.

Arguments#

INTO

Optional keyword between INSERT and the target; it has no effect on behavior.

table

The target table or view that receives the new rows.

( column list )

An optional, comma-separated list of the columns that receive values. Columns omitted from the list receive their default value (or NULL). If the column list is omitted, a value must be supplied for every column, in table order.

VALUES

One or more comma-separated row constructors, each a parenthesized list of expressions — VALUES (...), (...) — inserting one row per constructor.

DEFAULT VALUES

Inserts a single row using the default value of every column.

INSERT … SELECT

Inserts the result set of a SELECT query; the query’s columns must line up with the target columns.

Note

INSERT ... EXEC is accepted for compatibility only and is not executed, because stored procedures are not currently supported.

Examples#

Insert a single row, listing the target columns:

INSERT INTO dbo.Product (Id, Name, Price)
VALUES (1, 'Widget', 9.99);

Insert several rows at once:

INSERT INTO dbo.Product (Id, Name, Price)
VALUES (2, 'Gadget', 14.50),
       (3, 'Gizmo',  7.25);

Insert the result of a query:

INSERT INTO dbo.ProductArchive (Id, Name, Price)
SELECT Id, Name, Price
FROM   dbo.Product
WHERE  Discontinued = 1;

See also