The INSERT statement creates new rows in a table.
<insert_statement> ::=
INSERT [INTO] <table_name> [(<column_name>,...)]
VALUES (<insert_expression>,...) [<duplicates_clause>]
| INSERT [INTO] <table_name> [(<column_name>,...)]
<query_expression> [<duplicates_clause>]
| INSERT [INTO] <table_name> SET <set_insert_clause>,...
[<duplicates_clause>]
<insert_expression> ::= <extended_expression> | <subquery>
table_name, column_name, extended_expression, duplicates_clause, subquery, query_expression, set_insert_clause
The table name must denote an existing base table, view table (see Table), or a synonym.
If column names or a SET INSERT clause are specified, all of the specified column names must be columns in the table. If the table was defined without a key (that is, if the SYSKEY column is created internally by the database), the SYSKEY column must not occur in the sequence of column names or in a SET INSERT clause. A column must not occur more than once in a sequence of column names or in more than one SET INSERT clause.
The user must have the INSERT privilege for the table identified by the table name. If the table name identifies a view table, even the owner of the view table may not have the INSERT privilege because the view table cannot be changed.
A specified column (identified by column name or the column name in the set_insert_clause) is a target column. Target columns can be specified in any order.
· If a column name and SET INSERT clause are not specified, the result is the same as if a sequence of columns were specified that contains all of the columns in the table in the order specified in the CREATE TABLE statement or CREATE VIEW statement. In this case, every table column defined by the user is a target column.
· The number of expressions ( insert_expression) must be equal to the number of target columns.The ith expression is assigned to the ith column name.
· Expressions ( extended_expression) and subqueries (subquery) can be specified simultaneously.
· You can specify one or more subqueries.
· The specified subqueries must only return a single result line.
· The number of selected columns specified in the QUERY expression must be identical to the number of target columns.
· All mandatory columns of the table identified by table name must be target columns.
· If the table name identifies a view table, rows are inserted the base table(s) on which the view table is based. In this case, the target columns of the specified table name correspond to columns of the base tables, on which the view table is based. In the following, the term target column always refers to the corresponding column in the base table.
· Data type of the target column and data type of the value to be inserted
· Join view table in INSERT statement
· QUERY expression in INSERT statement
· Constraint definition in INSERT statement
In the case of the INSERT statement, the third entry of SQLERRD in the SQLCA is set to the number of inserted rows.
If errors occur when rows are inserted, the INSERT statement fails, and the table remains unmodified.