O'Reilly logo

SQL in a Nutshell by Kevin Kline

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

INSERT Statement

Synopsis

The INSERT statement adds rows of data to a table or view.

Platform

Command

DB2

Supported, with variations

MySQL

Supported, with variations

Oracle

Supported, with variations

PostgreSQL

Supported

SQL Server

Supported, with variations

The INSERT statement allows rows to be written to a table through one of several methods:

  • The first method is to insert one or more rows using the DEFAULT values specified for a column via the CREATE TABLE or ALTER TABLE statements.

  • 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 populates a table with many records at a time, is to insert the result set of a SELECT statement.

SQL2003 Syntax

INSERT INTO [ONLY] {table_name | view_name} [(column1 [,...] )]
[OVERRIDE {SYSTEM | USER} VALUES]
{DEFAULT VALUES | VALUES (value1 [,...]) | SELECT_statement }

Keywords

[ONLY]

Used on typed tables only, this optional keyword ensures that the values inserted into table_name do not insert into any subtables.

{table_name | view_name} [(column1 [,...] )]

Declares the updateable target table or view into which the records will be inserted. You must have INSERT privileges on the table or, at a minimum, on the columns that will receive the inserted values. If no schema information is included, as in scott.employee, then the current schema and user context are assumed. You may optionally include a list of the columns in the target table or view that will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required