SQL INSERT Statement

From GM-RKB
Jump to navigation Jump to search

A SQL INSERT Statement is a Data Insert Statement that is a SQL Statement (expressed in SQL).



References

2013

  • http://en.wikipedia.org/wiki/Insert_(SQL)
  • http://en.wikipedia.org/wiki/Insert_(SQL)#Basic_form
    • Insert statements have the following form:
      • INSERT INTO table (column1 [, column2, column3 ... ]) VALUES (value1 [, value2, value3 ... ])
    • The number of columns and values must be the same. If a column is not specified, the default value for the column is used. The values specified (or implied) by the INSERT statement must satisfy all the applicable constraints (such as primary keys, CHECK constraints, and NOT NULL constraints). If a syntax error occurs or if any constraints are violated, the new row is not added to the table and an error returned instead.
    • Example: <source lang="sql">INSERT INTO phone_book (name, number) VALUES ('John Doe', '555-1212');</source>
    • Shorthand may also be used, taking advantage of the order of the columns when the table was created. It is not required to specify all columns in the table since any other columns will take their default value or remain null:
      • INSERT INTO table VALUES (value1, [value2, ... ])
    • Example for inserting data into 2 columns in the phone_book table and ignoring any other columns which may be after the first 2 in the table. <source lang="sql">INSERT INTO phone_book VALUES ('John Doe', '555-1212');</source>