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
NOT DEFAULT
Indicates the column requires an entry (is mandatory).
WITH DEFAULT
Indicates that if no value is provided, 0 is inserted for numeric and money columns, or an empty string for character and date columns.
[WITH] DEFAULT default_spec | USER | NULL
Inserts the specified default value if the user or program does not provide a value for the column. The default value must be compatible with the data type of the column.
USER
Specifies the session's current user ID as the default value.
NULL
Specifies NULL as the default value for nullable columns.
If the DEFAULT clause is omitted, the column default depends on whether the column is nullable. Nullable columns default to nulls, and non-nullable columns are mandatory.
The following is an example of the DEFAULT option:
create table dept( dname character(10),
budget decimal default 100000.00,
creation date default date('01/01/94'));
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 or the declared length of the column, whichever is shorter.
• For fixed length string columns, if the column is wider than the default value, the default value is padded with blanks to the full 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 date columns, the default value must be a valid date specified using the date() function. If the time zone is omitted, the time zone defaults to the time zone of the user inserting the row.