(Contents)(Previous)(Next)

Creating Domains

Before defining a table, single columns can be defined separately as domains.

It would have been possible to say for the table 'person':

CREATE DOMAIN name CHAR(8).

This domain can be used later for the table definition:

CREATE TABLE person

(cno FIXED(4), - The cno is a four-digit number.

firstname name, - The first name and the name

name name, are eight characters long.

account FIXED(7,2)) - The account contains up to five

digits for dollar and two digits

for cent amounts.

A DOMAIN definition can include definitions for default values and constraints. Within a CONSTRAINT definition, the domain name must be used instead of the column name (see Section Column Constraints).

When default values are used, it must be ensured that these meet the constraints.

Another column is to be inserted into the table 'person' in order to record the birthday. This definition is also done by using a predefined DOMAIN. The current date is taken as the default value. A constraint is defined that the person was not born before the 01/01/1880.

CREATE DOMAIN birthday_dom

DATE DEFAULT DATE

CONSTRAINT birthday_dom > '01/01/1880' AND

birthday_dom <= DATE


(Contents)(Previous)(Next)