0% found this document useful (0 votes)
8 views

Integrity Constraints

Integrity constraints are rules that ensure data validity and consistency in a database. There are four main types of integrity constraints: domain constraints define valid values for columns, entity constraints require primary keys to be non-null, referential integrity constraints define relationships between tables, and key constraints ensure primary keys are unique and non-null.

Uploaded by

jubairahmed1678
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Integrity Constraints

Integrity constraints are rules that ensure data validity and consistency in a database. There are four main types of integrity constraints: domain constraints define valid values for columns, entity constraints require primary keys to be non-null, referential integrity constraints define relationships between tables, and key constraints ensure primary keys are unique and non-null.

Uploaded by

jubairahmed1678
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Integrity Constraints

What are Integrity Constraints in DBMS?

In Database Management Systems, integrity constraints


are pre-defined set of rules that are applied on the table
fields(columns) or relations to ensure that the overall
validity, integrity, and consistency of the data present in
the database table is maintained. Evaluation of all the
conditions or rules mentioned in the integrity constraint is
done every time a table insert, update, delete, or alter
operation is performed. The data can be inserted,
updated, deleted, or altered only if the result of the
constraint comes out to be True. Thus, integrity
constraints are useful in preventing any accidental damage
to the database by an authorized user.
Types of Integrity Constraints
Domain Constraint

Domain integrity constraint contains a certain set


of rules or conditions to restrict the kind of
attributes or values a column can hold in the
database table. The data type of a domain can be
string, integer, character, DateTime, currency, etc.
Example: Roll No Name Age Class
Consider a Student's table having Roll No, 101 Adam 14 6
Name, Age, Class of students. 102 Steve 16 8
In the above student's table, the value A in the
103 David 8 4
last row last column violates the domain
integrity constraint because the Class 104 Bruce 18 12
attribute contains only integer values 105 Tim 6 A
while A is a character.
Entity Integrity Constraint

Entity Integrity Constraint is used to ensure that the


primary key cannot be null. A primary key is used to identify
individual records in a table and if the primary key has a null
value, then we can't identify those records. There can be
null values anywhere in the table except the primary key
column.

ID Name Salary
Example:
Consider Employees table having Id, 1101 Jackson 40000
Name, and salary of employees 1102 Harry 60000
In the above employee's table, we can 1103 Steve 80000
see that the ID column is the primary 1104 Ash 1800000
key and contains a null value in the last Null James 36000
row which violates the entity
Referential Integrity Constraint

Referential Integrity Constraint ensures that there must always exist a valid
relationship between two relational database tables. This valid relationship
between the two tables confirms that a foreign key exists in a table. It
should always reference a corresponding value or attribute in the other
table or be null.

Referential Integrity Rule in DBMS is constraint applied on Primary key in


parent table which is Foreign key to the child table, which defines that
a Foreign key value of child table should always have the same Primary
key value in the parent table. So that, Reference from a parent table to
child table is valid.

Referential integrity is a constraint applied on foreign, which requires the


foreign key to have a matching primary key or provided primary key is not a
null value. Therefore, a constraint is specified between two tables, which
makes sure reference from a row in one table to another is valid.
Dept_ID Dept_Name ID Name Salary Dept_ID

1 Sales 1101 Jackson 40000 3

2 HR 1102 Harry 60000 2

3 Technical 1103 Steve 80000 4

1104 Ash 1800000 3


Department Table
1105 James 36000 1

Example: Employees Table

Consider an Employee and a Department table where Dept_ID acts as a foreign


key between the two tables Employees Table, Department Table.
In the above example, Dept_ID acts as a foreign key in the Employees table and a
primary key in the Department table.

Row having DeptID=4 violates the referential integrity constraint since DeptID 4 is
not defined as a primary key column in the Departments table.
Key constraint

Keys are the set of entities that are used to identify an


entity within its entity set uniquely. There could be multiple
keys in a single entity set, but out of these multiple keys,
only one key will be the primary key. A primary key can only
contain unique and not null values in the relational
database table.
Roll No Name Age Class
Example:
Consider a student's table. The last row 101 Adam 14 6
of the student's table violates the key
102 Steve 16 8
integrity constraint since Roll No 102 is
repeated twice in the primary key 103 David 8 4
column. A primary key must be unique
and not null therefore duplicate values 104 Bruce 18 12
are not allowed in the Roll No column of
102 Tim 6 2
the above student's table.
Conclusion

• Integrity Constraints in Database Management


Systems are the set of pre-defined rules responsible
for maintaining the quality and consistency of data in
the database.
• Evaluation against the rules mentioned in the integrity
constraint is done every time an insert, update, delete,
or alter operation is performed on the table.
• Integrity Constraints in DBMS are of 4 types:
– Domain Constraint
– Entity Constraint
– Referential Integrity Constraint
– Key Constraint
Thank You

You might also like