Column Definition for Local Tables
- Last Updated: May 15, 2020
- 2 minute read
- DataDirect Connectors
- JDBC
- IBM Db2 5.1
- MySQL 5.1
- Progress OpenEdge 5.1
- SAP Sybase 5.1
- Documentation
Purpose
Defines a column for local tables.
Syntax
column_name Datatype [(precision[,scale])]
[{DEFAULT default_value | GENERATED BY DEFAULT AS IDENTITY
(START WITH n[, INCREMENT BY m])}] | [[NOT] NULL]
[IDENTITY] [PRIMARY KEY]
where:
- column_name
- is the name to be assigned to the column.
- Datatype
- is the data type of the column to be created. See Data Types in the DataDirect Connect Series for JDBC User’s Guide for a list of supported Salesforce data types. You cannot specify ANYTYPE, BINARY, COMBOBOX, or TIME data types in the column definition of Create Table statements.
- precision
- is the number characters for CHAR and VARCHAR columns, the number of bytes for BINARY and VARBINARY columns, and the total number of digits for DECIMAL columns.
- scale
- is the number of digits to the right of the decimal point for DECIMAL columns and the number of fractional second digits for DATETIME columns.
- default_value
- is the default value to be assigned to the column. The following default values are
allowed in column definitions for local tables:
- For character columns, a single-quoted string or NULL. The only SQL function that can be used is CURRENT_USER.
- For datetime columns, a single-quoted Date, Time, or Timestamp value or NULL. You can also use the following datetime SQL functions: CURRENT_DATE, CURRENT_TIME, CURRENT_ TIMESTAMP, TODAY, or NOW.
- For boolean columns, the literals FALSE, TRUE, NULL.
- For numeric columns, any valid number or NULL.
- For binary columns, any valid hexadecimal string or NULL.
-
IDENTITY|GENERATED BY DEFAULT AS IDENTITY - define an auto-increment column. You can only specify these clauses on INTEGER and BIGINT columns. Identity columns are considered primary key columns, so a table can have only one Identity column.
- START WITH n[, INCREMENT BY m])
- specifies the sequence of numbers generated for the Identity column. n and m are the starting and incrementing values, respectively, for an Identity column. The default start value is 0 and the default increment value is 1.
Example A
Assuming the current schema is PUBLIC, a local table is created. id is an
identity column with a starting value of 0 and an increment value of 1 because no Start With
and Increment By clauses are specified.
CREATE TABLE Test (id INTEGER GENERATED BY DEFAULT AS
IDENTITY, name VARCHAR(30))
This example is equivalent to the previous example.
CREATE TABLE Test (id INTEGER IDENTITY, name VARCHAR(30))
Example B
Assuming the current schema is PUBLIC, a local table is created. id is an
identity column with a starting value of 2 and an increment of 2.
CREATE TABLE Test (id INTEGER GENERATED BY DEFAULT AS
IDENTITY (START WITH 2, INCREMENT BY 2), name VARCHAR(30))