Integrity Constraints ensure that changes made to the database by authorized users do not result in a loss of data consistency.
Integrity Constraints guard against accidental damage to the database.
The constraints on a single relation :
- not null
Not null constraint : name varchar2(10) not null
budget numeric(10,2) not null
i.e., ‘not null’ specification prohibits the insertion of a null value for the attribute.
unique constraint : unique (A1, A2,…,An)
Here, the set of attributes A1,A2,…An forms a candidate key.
i.e., with one value of candidate key, there will be at most one tuple in the relation.
Check clause : The use of ‘check clause’ is to ensure that attribute values satisfy specified conditions.
create table section
primary key (course_id, section_id, semester_id, year),
check (semester-id in (‘fall’, ‘winter’, ‘spring’, ‘summer’) ) ) ;
Here, We are creating a table with the following variables, and using the check clause we are checking whether the attribute values are satisfying the specified conditions.