CREATE TABLE SQL Command

Creates a DBF table using the specified fields. The complete syntax is:

CREATE TABLE | DBF Table_Name
[CODEPAGE = nCodePage]
(FieldName1 FieldType [( nFieldWidth [, nPrecision] )] [NULL | NOT NULL]
[AUTOINC [NEXTVALUE NextValue [STEP StepValue]]]
[, FieldName2 ... ] [ ... ] )

Parameters

Table_Name

Specifies the name of the DBF file to be created. The TABLE and DBF options are identical.

If no extension typed, the default ".dbf" is added to the result file. If DBF_Name is a relative file name (without path), the result file is created in the same directory, from where the last DBF file has been opened.
[nCodePage]

Specifies the code page to use. For the complete list of DBF code pages, see supported code pages topic.

FieldName1, FieldType, nFieldWidth, nPrecision

Specifies the field name, field type, field width, and field precision (number of decimal places) to be created, respectively. Maximal field count a DBF table can contain is 255 fields. If one or more fields allow null values, the limit decreases to 254 fields.
The FieldType parameter is a single letter (or long name) indicating the field type. You can specify nFieldWidth, nPrecision, or both for some of field types. The following table lists the values for FieldType and whether you can specify nFieldWidth and nPrecision:

Field Type Field Width Precision Data type
W, Blob Blob
C, Char, Character N Character field of width N
Y, Currency Currency
D, Date Date
T, DateTime DateTime
B, Double D Double
G, General General
I, Int, Integer Integer
L, Logical Logical
M, Memo Memo
N, Num, Numeric N D Numeric field of width N with D decimal places
F, Float N D Floating Numeric field of width N with D decimal places

The nFieldWidth and nPrecision parameters are ignored for the Blob, Currency, Date, DateTime, General, Integer, Logical, and Memo field types. If nPrecision is not included for the Numeric or Float types, the nPrecision parameter defaults to zero (no decimal places).

[NULL | NOT NULL]

Specifies whether null values are allowed in the field: NULL permits null values, NOT NULL does not allow null values. By default, NULL values are allowed (except AUTOINC fields)

[AUTOINC [NEXTVALUE NextValue [STEP StepValue]]]

Enables autoincrementing for the Integer field. NextValue specifies the start value and can be a positive or a negative value ranging from Integer range: -2,147,483,647 to 2,147,483,647. The default value is 1.
StepValue specifies the increment value for the field and can be a positive, nonzero integer value ranging from 1 to 255. The default value is 1.

Autoincrementing values cannot be NULL!
[FieldName2 ...] [ ... ]

Specifies one or more additional fields and attributes, and so on.

 

CREATE TABLE Example


Create a DBF file named "customer":

CREATE TABLE "D:\Data\customer.dbf" (id I AUTOINC NEXTVALUE 1 STEP 1, name C(40), payment F(5,2))

Create the same DBF file in Japanese Windows encoding and forbid NULL values in "payment" field:

CREATE TABLE "D:\Data\customer.dbf" CODEPAGE = 932 (id I AUTOINC NEXTVALUE 1 STEP 1, name C(40), payment F(5,2) NOT NULL)