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

Lecture 4 - Integrity Constraints

Uploaded by

chhavi22bca097
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)
3 views

Lecture 4 - Integrity Constraints

Uploaded by

chhavi22bca097
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/ 15

Lecture 4

Integrity
Constraints
Integrity Constraints
Referential Integrity Constraint
Referenced Relation

Referencing
Relation
Referential Integrity Constraint (Cont.)
🞆 Tuples in the referencing relation R1 have attributes FK (called
foreign key attributes) that reference the primary key attributes PK of
the referenced relation R2.

A tuple t1 in R1 is said to reference a tuple t2 in R2 if


t1[FK] = t2[PK].

R ……. ……. ……. PK R ……. FK


2 1
🞆 The value in the foreign key column (or columns) i.e. FK of the the
referencing relation R1 can be either:
a) a value of an existing primary key value of a corresponding primary
key PK in the referenced relation R2,
or
b) a null.
Referential Integrity Constraints

Referential integrity also includes the rules that

dictate what types of data manipulation are

allowed on referenced values and how these

actions affect dependent values.


Referential Integrity Constraints
Insertion No Violation

Referenced ● ON DELETE, NO ACTION


Relation
Deletion ● ON DELETE, CASCADE
( DEPT ) ● ON DELETE, SET NULL

Updation ● ON UPDATE, NO ACTION


● ON UPDATE, CASCADE
Referential ● ON UPDATE, SET NULL
Integrity
Constraint Insertion Restricted

Referencing Deletion
Relation No Violation
( EMP )
Updation Restricted
Referential Integrity Constraint - INSERTION

Insertion in
Referenced Relation is
allowed

Insertion in
Referencing
Relation is
restricted
Deletion/Updation in Referenced Relation

ON DELETE, CASCADE

ON UPDATE, CASCADE
Deletion/Updation in Referenced Relation

ON DELETE, SET NULL

ON UPDATE, SET NULL


Deletion/Updation in Referenced Relation

ON DELETE, NO ACTION

ON UPDATE, NO ACTION
Deletion in Referencing Relation
Updation in Referencing Relation
Primary key vs Foreign Key
Primary Key Foreign Key
• Helps you to uniquely • It is a field in the table that is
identify a record in the the primary key of another
table. table.

• A foreign key may accept


• Primary Key never accept multiple null values.
null values.
•A foreign key cannot
• Primary key is a clustered automatically create an
index and data in the DBMS index, clustered or non-
table are physically clustered. However, you can
organized in the sequence of manually create an index on
the clustered index. the foreign key.

• You can have multiple


• You can have the single foreign keys in a table.
Primary key in a table.
Summary
Thanks!!

You might also like