Define the term domain constraints.
Domain constraints are the most elementary form of integrity constraint. They are tested easily by the system whenever a new data item is entered into the database.
It is possible that several attributes can have the same domain. For example, the attributes customer-name and employee-name can have the same domain the set of all person names. However, the domains of balance and branch name certainly ought to be distinct. It is perhaps less clear whether customer name and branch-name should have the same domain.
The create domain clause can be used to define new domains. For example.
create domain Dollars numeric (12, 2)
define the domains Dollars to be decimal numbers with a total of 12 digits, two of which are placed after the decimal point. Values of one domain can be cast i.e., converted to other domain. SQL also provides drop domain and alter domain clauses to drop or modify domains that have been created earlier.
The check clause in SQL-92 permits domains to be restricted in powerful ways that most programming language type systems do not permit. For example, a check clause can ensure that an hourly wage domain allows only values greater than a specified value (such as the minimum wage), as shown below –
create domain hourly-wage numeric(5, 2)
constraint wage-value-test check(value >= 4.00)
The domain has a constraint that ensures that the hourly-wage is greater than 4.00. The clause constraint wage-value-test is optional, and is used to give the name wage-value-test to the constraint. The name is used to indicate which constraint an update violated.
The check clause can also be used to restrict a domain to not contain any null values, as shown below
create domain account-number char(10)
constraint account-number-mull-test check(value not null)
As another example, the domain can be restricted to contain only a specified set of values by using the in clause-
create domain account-type char(10)
check(value in(“Checking”, ‘Saving’))