Name

INSERT Statement

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

Platform

Command

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:

  • One or more rows can be inserted using the DEFAULT values specified for a column via the CREATE TABLE or ALTER TABLE statements.

  • The actual values to be inserted into each column of the record can be declared (this is the most common method).

  • The result set of a SELECT statement can be inserted into a table or view, populating it with many records simultaneously.

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 are not inserted into any subtables.

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

Declares the updatable 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, 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 receive data.

OVERRIDE {SYSTEM | USER} VALUES

Requires the SYSTEM keyword when inserting ...

Get SQL in a Nutshell, 3rd Edition 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.