Creating a New Table
Use the SQL DDL command CREATE TABLE to create a new table in the data grid.
Procedure
-
Compose a string with the following format:
CREATE TABLE [ IF NOT EXISTS ] <table_name> ( <column_name> <column_type> <column_constraint> [, <column_name> <column_type> <column_constraint>]... [, <table_constraint>] )Where:<column_constraint> = [ [CONSTRAINT <constraint_name>] NOT NULL | NULL | PRIMARY KEY ] <column_type> = (see SQL Data Type Mapping) <table_constraint> = [CONSTRAINT <constraint_name>] PRIMARY KEY (<column_name>[, <column_name>]...)
-
Pass the string to the ExecuteUpdate method of the tibdgSession object.
For example:
CREATE TABLE myTable (col1 INT PRIMARY KEY, col2 VARCHAR) CREATE TABLE IF NOT EXISTS myTable (col1 int NOT NULL, col2 varchar CONSTRAINT col2_pk PRIMARY KEY)
Note the following points when using the CREATE TABLE command:- Only columns with data types which map to ActiveSpaces long and string data types can be primary key columns. For more information, see SQL Data Type Mapping.
- Specifying a PRIMARY KEY column constraint and a PRIMARY KEY table constraint will cause an error.
- Specifying multiple columns with a PRIMARY KEY constraint will cause an error. Use the PRIMARY KEY table constraint instead.
- Specifying NOT NULL for primary key columns is optional. Primary key columns are implied to be NOT NULL.
- Specifying NULL for primary key columns will cause an error.
- For non-primary key columns, specifying NOT NULL will cause an error. ActiveSpaces treats all non-primary key columns as nullable.
- Specifying a length for string columns is ignored (for example, VARCHAR(255)). ActiveSpaces does not support limiting the length of string columns.
- Escaped names are not supported.
- Object names (for example, <column_name>, <index_name>, and <table_name>) are case insensitive. ActiveSpaces converts all object names to lowercase prior to executing the command.
Copyright © Cloud Software Group, Inc. All rights reserved.
