TurboSQL Guide

INSERT Statement

Previous  Top  Next


Adds one or more new rows of data in a table

INSERT INTO table_reference
[(columns_list)]
VALUES (update_atoms)

Description

Use the INSERT statement to add new rows of data to a table.

Use a table reference in the INTO clause to specify the table to receive the incoming data.

The columns list is a comma-separated list, enclosed in parentheses, of columns in the table and is optional. The VALUES clause is a comma-separated list of update atoms, enclosed in parentheses. If no columns list is specified, incoming update values (update atoms) are stored in fields as they are defined sequentially in the table structure. Update atoms are applied to columns in the order the update atoms are listed in the VALUES clause. There must also be as many update atoms as there are columns in the table.

INSERT INTO "holdings.dat"
VALUES (4094095, "BORL", 5000, 10.500, 2.1.1998)

If an explicit columns list is stated, incoming update atoms (in the order they appear in the VALUES clause) are stored in the listed columns (in the order they appear in the columns list). NULL values are stored in any columns that are not in a columns list.

INSERT INTO "customer.dat"
(custno, company)
VALUES (9842, 'dataweb GmbH')

To add rows to one table from another, omit the VALUES keyword and use a subquery as the source for the new rows.

INSERT INTO "customer.dat"
(custno, company)
SELECT custno, company
FROM "oldcustomer.dat"