INSERT SQL Command

Appends a new record to the end of a table and fills corresponding fields with specified values. The syntaxes:

INSERT INTO dbf_filename [(Field1 [, Field2, ...])]
VALUES (Expression1 [, Expression2, ...])

Use this syntax to simple insert the values into specified fields in a table.

INSERT INTO dbf_filename [(FieldName1 [, FieldName2, ...])]
SELECT SELECTClauses [UNION UnionClause SELECT SELECTClauses ...]

Use this syntax to insert rows from a nested SQL SELECT command.

Parameters

INSERT INTO dbf_filename

Specifies the name of the DBF file for appending a new row. If dbf_filename contains file name only (without path), this DBF file is being looked at the same directory, from where the last DBF file was opened.
If the table hasn't been opened, DBF Commander opens the file automatically. It remains open after the query is complete.

In order to fast insert full file name into SQL query text, use the Insert Current Filename command
[( Field1 [, Field2 [, ...]])]

Specifies the field names of the new record into which the values are inserted.

VALUES (Expression1 [, [table_alias.]Expression2 [, ...]])

Specifies the values to be inserted into the fields of the new record. If you omit the field names, you must specify the field values in the order defined by the table structure. Use the table alias if the Expression is a name of a field.

INSERT command attempts to insert NULL values into any columns not specified in the VALUES clause. If any of these fields does not allow NULL values, error "Field field_name does not accept null values" appears.
SELECT SELECTClauses [UNION UnionClause SELECT SELECTClauses ...]

For insertion into DBF table this variant of syntax retrieves data from specified fields of another DBF file, using one or more SQL SELECT statements.

When you try to insert data with INSERT command, make sure that the values you insert is compatible with the field types into which you are inserting. Otherwise, there are possible "Data type mismatch" errors or data loss.

 

INSERT Example

Insert one record into "orders" DBF table:

INSERT INTO "D:\Data\orders.dbf" (to_country, ship_count, order_date, freight) VALUES ('Germany', NULL, CTOD('01.31.2012'), 58.12)

In the example below, at first the SELECT statement selects values for the last month from "country" field of "customer" DBF file. Then the result values are inserted into "orders" table:

INSERT INTO "D:\Data\orders.dbf" (to_country) SELECT country FROM "D:\Data\customer.dbf" WHERE order_date >= (DATE()-30)