|
|
INSERT
Inserts one or more rows into a table or view.
where
columns-values-specificationis:Usage
Embedded/Interactive/ODBC/Procedural/JDBC.
Description
One or more new rows are inserted into the table or view specified in
table-name.If a list of column names is given in
columns-values-specification, only the specified columns are assigned values in accordance with the INSERT statement.The columns not listed are assigned their default value or the NULL value in accordance with the column definition, see CREATE TABLE. If
table-namespecifies a view, any columns in the base table which are excluded from the view are also assigned their default value or theNULLvalue in the same way.If the column name list is omitted, all columns in the table or view are implicitly specified in the order in which they are defined in the table or view. This practice is, however, not recommended when
INSERTstatements are embedded in application programs, since the semantics of the statement will change if the table or view definition is changed.Specification of a
DEFAULT VALUESclause inserts a single row into the table with the column default value specified for each column in the table.Values are assigned in order from the items in the
VALUESclause or the select-specification to the columns that have been explicitly or implicitly specified. The number of values specified must be the same as the number of columns and the data type of each value must be assignment-compatible with the column into which it is to be inserted.Specification of a
VALUESclause inserts a single row into the table or view. The keywordNULLorDEFAULTcan be specified in theVALUESclause to insert theNULLvalue or the column default value, respectively, into the corresponding column.Specification of a select-specification instead of a
VALUESclause inserts the set of rows resulting from the select-specification into the target table or view. If the set of rows resulting from the select-specification is empty, aNOT FOUNDcondition code is returned, see Return Status and Conditions.Language Elements
expression, see Expressions.
select-specification, see The SELECT Expression.Restrictions
INSERTaccess is required on the table or view specified in theINTOclause.If a select-specification is specified,
SELECTaccess is required on the table(s) from which the selection is performed.In a procedural usage context, the
INSERTstatement is only permitted if the procedureaccess-clauseisMODIFIES SQL DATA, see CREATE PROCEDURE.Notes
Expressions used in the
VALUESclause cannot refer to column names or set functions.If the row or rows inserted do not conform to constraints imposed on the table, no rows are inserted. Constraints are as follows:
- Values in the primary key and unique keys of the base table may not be duplicated. This also applies to unique secondary indexes.
FOREIGN KEYconstraints must be observed.CHECKconstraints in table, column and domain definitions must be observed for insertions.- For insertion into views defined
WITH CHECK OPTION, inserted values must conform to the view definition.Example
INSERT INTO countries (country_code, country, currency_code) VALUES ('CX', 'Christmas Island', 'AUD');Standard Compliance
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|