SQL support / Static SQL statements |
Creates a new row in a database table.
INSERT INTO table-specification [ ( column [,...] ) ] { VALUES ( { variable | sql-expression } [,...] ) | select-statement }
INSERT INTO table-specification VALUES ( record.* )
INSERT INTO table-specification VALUES record.*where table-specification is:
[dbname[@dbserver]:][owner.]table
The INSERT SQL statement can be used to create a row i specified database table.
The dbname, dbserver and owner prefix of the table name should be avoided for maximum SQL portability.
When using the VALUES clause, the statement inserts a row in the table with the values specified in variables, as literals, or with NULL. If a record is available, you can specify all record members with the star notation (record.*).
The third syntax can be used to avoid serial column usage in the value list: The record member corresponding to a column defined as SERIAL, SERIAL8 or BIGSERIAL in the schema file will be removed by the compiler. This is useful when using databases like Microsoft™ SQL Server, where IDENTITY columns must be omitted in INSERT statements.
When using a select-statement, the statement insert all rows returned in the result set of the SELECT statement. The columns returned by the result set must match the column number and data types of the target table. For SQL portability, it is not recommended that you use this syntax.
MAIN DEFINE myrec RECORD key INTEGER, name CHAR(10), cdate DATE, comment VARCHAR(50) END RECORD DATABASE stock LET myrec.key = 123 LET myrec.name = "Katos" LET myrec.cdate = TODAY LET myrec.comment = "xxxxxx" INSERT INTO items VALUES ( 123, 'Practal', NULL, myrec.comment ) INSERT INTO items VALUES ( myrec.* ) INSERT INTO items VALUES myrec.* -- without serial (if one is used) INSERT INTO items SELECT * FROM histitems WHERE name = myrec.name END MAIN