CREATE TABLE

<< Click to Display Table of Contents >>

Navigation:  Apollo SQL > DDL & DML Statements >

CREATE TABLE

The CREATE TABLE command is used to create new data tables. A table name and corresponding list of column definitions required.

image\tip.gif Apollo products implement an "ExecSQL" method or function which must be used to execute a CREATE TABLE or ALTER TABLE statement.

Syntax:

CREATE TABLE table_reference (column_definition [, column_definition,...]

[primary_key_constraint])

 

Column definitions consist of a comma-separated list of combinations of column name, data type, and (if applicable) dimensions. The list of column definitions must be enclosed in parentheses. The number and type of dimensions that must be specified varies with column type. See the section on defining column types for specific syntax of all supported column types.

Use the PRIMARY KEY keyword to create a structural index (.CDX/.NSX) for the new table. The PRIMARY KEY clause does not work with Clipper .NTX files. This will create a tag called PRIMARY in the structural .CDX or .NSX index file (having the same base name as the .DBF).

CREATE TABLE Example:

The following statement creates a new table called TEST.DBF with a PRIMARY KEY constraint on the LAST_NAME and FIRST_NAME columns:

CREATE TABLE MyTable

(

last_name CHAR(20),

first_name CHAR(15),

salary FLOAT(10,2),

dept_no SMALLINT

PRIMARY KEY (last_name, first_name)

)

 

See supported Data Types for field definitions.