# RELATIONSHIP  THE WAY TABLES ARE RELATED  A TABLE MUST PARTICIPATE IN AT LEAST ONE RELATIONSHIP  IN A BINARY RELATIONSHIP TWO ENTITIES PARTICIPATE 

## Presentation on theme: "RELATIONSHIP  THE WAY TABLES ARE RELATED  A TABLE MUST PARTICIPATE IN AT LEAST ONE RELATIONSHIP  IN A BINARY RELATIONSHIP TWO ENTITIES PARTICIPATE "— Presentation transcript:

RELATIONSHIP  THE WAY TABLES ARE RELATED  A TABLE MUST PARTICIPATE IN AT LEAST ONE RELATIONSHIP  IN A BINARY RELATIONSHIP TWO ENTITIES PARTICIPATE  1:1or1:MorM:N

HOW TO IMPLEMENT?  (1:1) THE PRIMARY KEY OF ONE TABLE IS INCLUDED AS AN ATTRIBUTE TO THE OTHER TABLE.  THIS IS KNOWN AS FOREIGN KEY.

HOW TO IMPLEMENT?  (1:M) THE PRIMARY KEY OF THE 1 SIDE TABLE IS ADDED AS AN ATTRIBUTE TO THE MANY SIDE TABLE.  THIS IS KNOWN AS FOREIGN KEY.

HOW TO IMPLEMENT?  (M:N) CREATE A NEW TABLE.  PRIMARY KEY OF THE NEW TABLE IS THE COMBINATION OF THE PRIMARY KEY OF THE M-SIDE AND N-SIDE TABLE.  WE CAN ADD NEW ATTRIBUTE FOR THE RELATION  THEY ARE KNOWN AS FOREIGN KEYS.

HOW TO CREATE?  FROM THE MAIN MENU BAR SELECT o TOOLS ► RELATIONSHIP  THEN ADD THE TABLES  THEN DRAG PKs TO FKs

HOW TO CREATE?

REFERENTIAL INTEGRITY

 USING KEY AND DATA CONSTRAINTS WE MAINTAIN THE INTEGRITY OF DATA IN A FIELD OR IN A TABLE.  USING REFERENTIAL CONSTRAINT WE MAINTAIN INTEGRITY AMONG TABLES IN A DATABASE.  WE DEFINE THEM DURING CREATION OF RELATIONSHIP.

TYPES OF REFERENTIAL INTEGRITY CONSTRAINTS (RI)  RESTRICTED DELETES  RESTRICTED INSERTS  CASCADE DELETES  CASCADING UPDATES

RESTRICTED DELETES  MEANS A PARENT RECORD CANNOT BE DELETED IF CHILD RECORD EXISTS.  WE MUST UNCHECK THE Cascade Delete Related Records CHECK BOX IN THE Edit Relationship DIALOG BOX.

RESTRICTED DELETES

RESTRICTED INSERTS  MEANS A CHILD RECORD CANNOT REFERENCE A NON EXISTENT PARENT RECORD.  IF A CHILD RECORD REFERENCE A RECORD THAT IS NOT IN THE PARENT TABLE THIS IS KNOWN AS ORPHAN RECORDS.  THE DBMS AUTOMATICALLY IMPLEMENTS THIS CONSTRAINT.

CASCADING DELETES  MEANS IF A PARENT RECORD IS DELETED ALL RELATED CHILD RECORDS ARE ALSO DELETED AUTOMATICALLY.  WE SHOULD CHECK THE Cascade Delete Related Records CHECK BOX IN THE Edit Relationship DIALOG BOX.