Previous | Home | Next |
A default constraint can be used to assign a constant value to a column, and the user need not insert values for such a column . Only one DEFAULT constraint values can be created for a column , but the column cannot be an IDENTITY column. The system-supplied values like USER, CURRENT_USER, and user defined values can be assigned as defaults.
CREATE TABLE table_name (column_name data_type DEFAULT [constant_expression])
where, constraint_name specifies the name of the constraint to be created.
constant_expression specifies an expression that contains only constant values and can contain NULL.
Example:
CREATE TABLE employee (cCity char (14) DEFAULT 'New Delhi', emp_id varchar(15))
The above command use to create a DEFAULT constraint on the cCity attribute. If a city is not specified, then the cCity attribute would contain 'New Delhi' by default.
output