When you create a table, you can define a domain for each column.
CREATE TABLE
customer
(cno FIXED(4) PRIMARY KEY CONSTRAINT cno_cons CHECK
cno > 0,
title CHAR(7) CONSTRAINT title_cons CHECK title
IN ('Mr','Mrs','Company'),
firstname CHAR(10),
name CHAR(10) NOT NULL,
...)
The customer number consists of four digits, the title is seven characters long, and the first and last names are each 10 characters long.
See also:
CREATE TABLE Statement (create_table_statement)
You can predefine these domains in a domain definition.
To create a domain, use the CREATE DOMAIN statement.
CREATE DOMAIN name_domain CHAR(10)
Names are to be ten characters long.
The relevant CREATE TABLE statement could therefore be formulated as follows:
CREATE TABLE
customer
(cno FIXED(4) PRIMARY KEY
CONSTRAINT cno_cons CHECK cno > 0,
title CHAR(7) CONSTRAINT
title_cons CHECK title IN ('Mr','Mrs','Company'),
firstname name_domain,
name name_domain NOT NULL,
...)
First and last names are each 10 characters long.
In a domain definition, you can specify a DEFAULT value and/or a CONSTRAINT definition.
· The DEFAULT values must satisfy any existing restrictive conditions.
· No constraint name can be specified in the CONSTRAINT definition and the domain is used as the column name.
CREATE DOMAIN
birthday_domain DATE DEFAULT DATE
CONSTRAINT birthday_domain> '1880-01-01' AND birthday_domain
<= DATE
In the domain definition birthday_domain for the birthday, the current date is selected as the DEFAULT value. The birth date is not to be before 01/01/1880.
ALTER TABLE person ADD birthday birthday_domain
The birthday column with the domain definition birthday_domain was added to the person table.
See also:
CREATE DOMAIN Statement (create_domain_statement)
To drop a domain, use the DROP DOMAIN statement:
DROP DOMAIN name_domain
You can use this SQL statement to drop the domain definition. Table definitions that used this domain definition are not dropped.
See also:
DROP DOMAIN Statement (drop_domain_statement)