You can use the CREATE
TABLE statement to create column defaults at the time a
table is created, or the ALTER TABLE statement
to add column defaults at a later time.
You can also specify a default
value when creating a user-defined domain (data type) using the CREATE
DOMAIN statement.
The stored procedure sp_iqcolumn returns
information abut all columns for all tables. One of the column returned
by the result set of sp_iqcolumn is
called “default,” and shows the particular default
value for that column.
- To create a table named tab1 with
the default special value LAST USER specified
for the CHARACTER column c1:
CREATE TABLE tab1(c1 CHAR(20) DEFAULT LAST USER)
- To add a condition to an existing column named id in
the sales_order table, so that the
value of the column automatically increments (unless a client application
specifies a value):
ALTER TABLE sales_order MODIFY id DEFAULT AUTOINCREMENT
- To define a domain named dom1with
a data type of INTEGER and a default value
of 45:
CREATE DOMAIN dom1 INTEGER DEFAULT 45