A table is DBMS is a set of rows and columns that contain data. Columns in table have a unique name, often referred as attributes in DBMS. A domain is a unique set of values permitted for an attribute in a table. For example, a domain of month-of-year can accept January, February….December as possible values, a domain of integers can accept whole numbers that are negative, positive and zero.
Definition: Domain constraints are user defined data type and we can define them like this:
Domain Constraint = data type + Constraints (NOT NULL / UNIQUE / PRIMARY KEY / FOREIGN KEY / CHECK / DEFAULT)
For example I want to create a table “student_info” with “stu_id” field having value greater than 100, I can create a domain and table like this:
create domain id_value int constraint id_test check(value > 100); create table student_info ( stu_id id_value PRIMARY KEY, stu_name varchar(30), stu_age int );
I want to create a table “bank_account” with “account_type” field having value either “checking” or “saving”:
create domain account_type char(12) constraint acc_type_test check(value in ("Checking", "Saving")); create table bank_account ( account_nbr int PRIMARY KEY, account_holder_name varchar(30), account_type account_type );
Leave a Reply