Jump to content

Insert (SQL)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dze27 (talk | contribs) at 01:18, 16 August 2004 (initial entry). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A SQL INSERT statement adds a record to a table in a relational database.

Insert statements have the following form:

INSERT INTO table (field1, [field2, ... ]) VALUES (value1, [value2, ...])

The number of fields and values must be the same. All of the mandatory (NOT NULL) fields must be specified and any of the optional fields may be specified. No field may be repeated.

Example:

INSERT INTO Phone_book (Name, Number) VALUES ('John Doe', '555-1212')

Common reasons for an INSERT statement failing include the following

  • failure to include values for fields that may not be NULL
  • duplication of the table's primary key
  • violation of other database constraints