8. SQL Statements : CREATE TABLE : Column Specification--Define Column Characteristics : Default Clause
 
Share this page                  
Default Clause
The WITH|NOT DEFAULT clause in the column specification specifies whether a column requires an entry.
This clause has the following format:
[WITH] DEFAULT default_spec | WITH DEFAULT | NOT DEFAULT
[WITH] DEFAULT default_spec
Indicates that if no value is provided (because none is required), the DBMS Server inserts the default value. The default value must be compatible with the data type of the column.
For character columns, valid default values include the following constants:
USER
CURRENT_USER
SYSTEM_USER
For boolean columns, valid default values include FALSE or TRUE.
WITH DEFAULT
Indicates that if no value is provided, the DBMS Server inserts 0 for numeric and money columns, an empty string for character columns, an empty string for Ingres date columns, the current date for ANSI date columns, and the current timestamp for timestamp columns.
NOT DEFAULT
Indicates the column is mandatory (requires an entry).
The following is an example of using the DEFAULT clause:
CREATE TABLE DEPT(dname    CHAR(10),
    location      CHAR(10)   DEFAULT 'NY',
    creation      DATE       DEFAULT '01/01/03',
    budget        MONEY      DEFAULT 10000);
Restrictions on the Default Value for a Column
The following considerations and restrictions apply when specifying a default value for a column:
The data type and length of the default value must not conflict with the data type and length of the column.
The maximum length for a default value is 1500 characters.
For fixed-length string columns, if the column is wider than the default value, the default value is padded with blanks to the declared width of the column.
For numeric columns that accept fractional values (floating point and decimal), the decimal point character specified for the default value must match the decimal point character in effect when the value is inserted. To specify the decimal point character, set II_DECIMAL.
For money columns, the default value can be exact numeric (integer or decimal), approximate numeric (floating point), or a string specifying a valid money value. The decimal point and currency sign characters specified in the default value must match those in effect when the value is inserted.
For date columns, the default value must be a string representing a valid date. If the time zone is omitted, the time zone defaults to the time zone of the user inserting the row.
For user-defined data types (UDTs), the default value must be specified using a literal that makes sense to the UDT. A default value cannot be specified for a logical key column.
For spatial data types, you cannot specify a default value.