Integrity Constraints
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
- unique
- check
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.
Example-1 :
create table section
(course_id varchar2(9),
section_id varchar2(2),
semester-id varchar2(6),
year numeric(4)
room_number numeric(4),
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.
Integrity Constraints