Name

INSERT

Synopsis

The INSERT statement adds rows of data to a table or view. The INSERT statement allows records to be entered into a table through one of several methods:

  • The first method is to insert records using the DEFAULT values created on the columns given table via the CREATE TABLE or ALTER TABLE statements. (This method is not supported by Oracle.)

  • The second and most common method is to declare the actual values to be inserted into each column of the record.

  • The third method, which quickly populates a table with many records, is to insert the result set of a SELECT statement into a table.

Vendor

Command

SQL Server

Supported, with variations

MySQL

Supported, with variations

Oracle

Supported, with variations

PostgreSQL

Supported

SQL99 Syntax and Description

INSERT [INTO] [[database_name.]owner.] {table_name | view_name} [(column_
    list)]
{[DEFAULT] VALUES | VALUES (value[,...]) | SELECT_statement }

To use the INSERT statement, first declare the table (or view) where the data is to be inserted. The INTO keyword is optional. Specify the columns in the table that receives data by enclosing them in parentheses separated by commas in the column_list. The column_list can be left off, but all columns that are defined for the table are then assumed.

The DEFAULT VALUES method is mutually exclusive from the list_of_values and SELECT_statement methods.

The INSERT . . . VALUES statement adds a single row of data to a table using literal values supplied in the statement. The

Get SQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.