Domain constraints are used to maintain value according to user specification
Domain constraints are:
1. Not null-such constraints are applied to an attribute when we have to specify that the attribute cannot accept null value. Null is in the domain of all attributes unless not null is applied.
Example: Consider the schema student.Student{rollno, name,sscper}. The name of the student should not be null. So we can apply the not null constraint to the name attribute.
General syntax (While creating table)
Create table tablename(attr1 datatype(size), attr2 datatype(size) not null,attr3 datatype(size));
After creating the table
Alter table tablename modify attr not null;
Example:
Create table student(rollno number(5),name varchar(30) not null,sscper number(3));
Alter table student modify name not null;
2. Check – allows enforcing domain integrity by limiting the values accepted by an attribute.
Eg: consider an attribute age of the entity employee. If age should be limited to 60, check constraint can be used
General syntax:
Create table tablename(attr1 datatype(size),attr2 datatype(size)
constraint nameofconstraint check(attr<value));
or