skip to main content
Designing and coding the IP : DDL object management : Create Table processing
 

Create Table processing

The supported SQL syntax for creating a table is:
CREATE TABLE table_name (column-element, column element...)
column-element = column-definition
| [CONSTRAINT constraint-name] table-constraint-definition
column-definition = column-identifier data-type [DEFAULT default-value] [column-constraint [column-constraint]...]
column-constraint = NULL | NOT NULL | UNIQUE [KEY] | PRIMARY KEY
| REFERENCES pkey-table-name [pkey-column-identifier]
| USERDATA 'literal string'
table-constraint-definition = UNIQUE [KEY] (column-identifier
[,column-identifier]...)
| PRIMARY KEY (column-identifier [,column-identifier]...)
| FOREIGN KEY (column-identifier [,column-identifier]...)
REFERENCES pkey-table-name (pkey-column-identifier [,pkey-column-identifier]…)
| NESTED KEY (column-identifier [,column-identifier]...)
REFERENCES pkey-table-name
 
Table 9: CREATE TABLE data types 
SQL data type
Description
Data type
BINARY
Fixed length binary data.
XO_TYPE_BINARY
BIT
One or a zero.
XO_TYPE_BIT
CHAR(N)
ASCII String of maximum length. N
XO_TYPE_CHAR
DATE
Date field.
XO_TYPE_DATE
DECIMAL
OpenAccess SDK internally only supports NUMERIC data. The IP must convert DECIMAL types to equivalent NUMERIC types when returning the schema information.
XO_TYPE_NUMERIC
DECIMAL(M)
Numeric value with precision M and scale 0.
XO_TYPE_NUMERIC
DECIMAL(M,N)
Numeric value with precision M and scale N.
XO_TYPE_NUMERIC
DOUBLE | DOUBLE PRECISION
Double precision floating point number.
XO_TYPE_DOUBLE
FLOAT[(M)]
Double precision floating point number.
XO_TYPE_FLOAT
INTEGER
C type long int.
XO_TYPE_INTEGER
LONGVARBINARY
A variable length binary stream with no maximum.
XO_TYPE_LONGVARBINARY
LONGVARCHAR
A variable length ASCII string (CLOB).
XO_TYPE_LONGVARCHAR
NUMERIC
IP specific default precision and scale.
XO_TYPE_NUMERIC
NUMERIC(M)
Numeric value with precision M and scale 0.
XO_TYPE_NUMERIC
NUMERIC(M,N)
Numeric value with precision M and scale N.
XO_TYPE_NUMERIC
REAL
Single precision floating point number.
XO_TYPE_REAL
SMALLINT
C type short int.
XO_TYPE_SMALLINT
TIME
Time field.
XO_TYPE_TIME
TIMESTAMP
Time/date field.
XO_TYPE_TIMESTAMP
TINYINT
Integer in the range 0 to 255.
XO_TYPE_TINYINT
VARBINARY(N)
A variable length binary stream of maximum length N.
XO_TYPE_VARBINARY
VARCHAR(N)
A variable length ASCII string of maximum length N.
XO_TYPE_VARCHAR
WCHAR(N)
Unicode String of maximum length N.
XO_TYPE_WCHAR
WLONGVARCHAR
A variable length Unicode string (CLOB).
XO_TYPE_WLONGVARCHAR
WVARCHAR(N)
A variable length Unicode string of maximum length N.
XO_TYPE_WVARCHAR
When a SQL query of this form is issued, the OpenAccess SDK SQL engine maps this information into a list of schema objects of types damobj_table, damobj_column, damobj_stat and damobj_fkey. The following table shows how the CREATE TABLE query is mapped into the schema objects.
 
Table 10: CREATE TABLE syntax to schema objects mapping 
Schema object properties
CREATE TABLE syntax
Remarks
damobj_table
table_qualifier
table_owner
table_name
CREATE TABLE [qualifier].[owner].table_name
The table information is mapped to the schema object of type DAMOBJ_TYPE_TABLE.
damobj_column
column_name = column-identifier
data_type=XO_TYPE_XXX
char_max_length =N (Set for CHAR and VARCHAR fields)
numeric_precision = M (Set for NUMERIC fields)
numeric_scale = N (Set for NUMERIC fields)
nullable = XO_NO_NULLS (If NOT NULL clause is specified. Otherwise set to XO_NULLABLE)
userdata (Set if the USERDATA clause was defined for the column)
userdata = “DEFAULT default-value”
seq_in_index=1
column-identifier data-type NOT NULL
USERDATA 'literal string'
DEFAULT default-value
Each part of the column information (name, data-type, length, precision, scale, nullable, userdata) is mapped to one schema object of type DAMOBJ_TYPE_COLUMN.
damobj_stat
column_name = column name for which the indexing information is specified
non_unique = FALSE (If UNIQUE KEY is specified. Else set to TRUE)
type = DAM_INDEX_PRIMARY_KEY If PRIMARY KEY is specified or DAM_INDEX_UNIQUE_KEY if UNIQUE KEY is specified. The type field is not set in otherwise.)
column-constraint clauses:
UNIQUE KEY | PRIMARY KEY
The index information, if any, for each column is mapped to one schema object of type DAMOBJ_TYPE_STAT.
damobj_stat
column_name = column name for which the indexing information is specified
index_name = constraint-name
non_unique = FALSE
type = DAM_INDEX_UNIQUE_KEY or DAM_INDEX_PRIMARY_KEY
seq_in_index = order of the index column starting at 1
table-constraint clause:
[CONSTRAINT constraint-name] UNIQUE KEY (column-identifier ...)
Each column that is specified in the column list is mapped to a damobj_stat and the seq_in_index represents the order of these columns.
damobj_stat
column_name = column name for which the indexing information is specified
index_name = constraint-name
non_unique = FALSE
type = DAM_INDEX_PRIMARY_KEY
seq_in_index = order of the index column starting at 1
table-constraint clause:
[CONSTRAINT constraint-name] PRIMARY KEY (column-identifier ...)
Each column that is specified in the column list is mapped to a damobj_stat and the seq_in_index represents the order of these columns.
damobj_fkey
pktable_name = pkey-table-name as specified in the REFERENCES clause.
pkcolumn_name = pkey-column-identifier as specified in the REFERENCES clause.
fktable_name = table name of the current table that is being created
fkcolumn-name = column name of the current table for which the REFERENCES clause is specified
REFERENCES pkey-table-name pkey-column-identifier
The foreign key information if any for each column is mapped to schema object of type DAMOBJ_TYPE_FKEY.
damobj_fkey
pktable_name = pkey-table-name as specified in the REFERENCES clause.
pkcolumn_name = pkey-column-identifier as specified in the REFERENCES clause.
fktable_name = table name of the current table that is being created
fkcolumn-name = corresponding column name from the foreign key column list
key_seq = order of the index column starting at 1
fk_name = constraint-name
pk_name = “FOREIGN KEY”
table-constraint clause:
[CONSTRAINT constraint-name] FOREIGN KEY (column-identifier ...) REFERENCES pkey-table-name (pkey-column-identifier...)
Each column that is specified in the column list is mapped to a damobj_fkey and the key_seq represents the order of these columns.
damobj_fkey
pktable_name = pkey-table-name as specified in the REFERENCES clause.
pkcolumn_name = NULL.
fktable_name = table name of the current table that is being created
fkcolumn-name = corresponding column name from the foreign key column list
key_seq = order of the index column starting at 1
fk_name = constraint-name
pk_name = “NESTED KEY”
table-constraint clause:
[CONSTRAINT constraint-name] NESTED KEY (column-identifier...) REFERENCES pkey-table-name
Each column that is specified in the column list is mapped to a damobj_fkey and the key_seq represents the order of these columns.