SlideShare a Scribd company logo
1 of 29
Download to read offline
CHAPTER 3

Degree of relationship
Degree of relationship refers to the number
of participating entities in a relationship.

Dr.Girija Narasimhan

1
Unary Relationship

Subjects may be prerequisites for
other subjects.

Dr.Girija Narasimhan

2
M:N unary relationship: A Subject may have
many other Subjects as prerequisites and each
Subject may be a prerequisite to many other
Subjects

1:M unary relationship:
An Employee may manage many Employees,
but an Employee is managed by only one
Employee

1:1 unary relationship:
A Person may be married to only one Person.

Dr.Girija Narasimhan

3
Binary Relationship
If there are two entities involved in relationship then it is
referred to as binary relationship.

Dr.Girija Narasimhan

4
Ternary Relationship

If there are three entities involved then it is called as ternary relationship and so on.

The University might need to record which
teachers taught which subjects in which
courses.
Dr.Girija Narasimhan

5
The cardinality of a relationship is the number of instances of entity B that can be
associated with entity A. There is a minimum cardinality and a maximum cardinality for
each relationship, with an unspecified maximum cardinality being shown as
N. Cardinality limits are usually derived from the organizations policies or external
constraints.

At the University, each Teacher can teach an
unspecified maximum number of subjects as
long as his/her weekly hours do not exceed 24
(this is an external constraint set by an
industrial award). Teachers may teach 0
subjects if they are involved in non teaching
projects. Therefore, the cardinality limits for
TEACHER are (O,N).

Dr.Girija Narasimhan

The University's policies state that each
Subject is taught by only one teacher,
but it is possible to have Subjects that
have not yet been assigned a
teacher. Therefore, the cardinality limits
for SUBJECT are (0,1).

6
Relation

Relation schema

Employee Table

Relation (R )
Attributes
(A1,A2…An)

Employee (Emp_id,ename,Salary)
Foreign key

Primary key or identifier

Employee (Emp_id,ename,Salary)

Employee (Emp_id,ename,Salary,dept_name)
Foreign key

Composite key

Department(dept_name,ename,Salary)

Over_time (emp_id, dept_name,No_of_hour)

Composite key
Dr.Girija Narasimhan

7
INTEGRITY CONSTRAINTS
DOMAIN
CONSTRAINTS

ENTITY Integrity
CONSTRAINTS

Dr.Girija Narasimhan

Referential
Integrity
CONSTRAINTS

8
DOMAIN CONSTRAINTS

Domain_name

Meaning

Data type

Age

Years of the person

Phone_no

Conduct number

Mark

size

number

3

number

Scored by Student
in Exam

number

Dr.Girija Narasimhan

8

3

Allowable value or range
<=110
Must be 8 digit and
<99999999 and
>90000000

>=0 and <=100

9
ENTITY Integrity CONSTRAINTS
Every relation must have primary key
Every primary key attribute is non- null and unique

Unique means, value of the primary key must
be different not be same.
Null is a value, suppose no other value not assign or apply.
Null is not zero (0) or blank (“ “)

Dr.Girija Narasimhan

10
ENTITY Integrity CONSTRAINTS
Not Unique
Department

Entity integrity not enforced

Not Unique

Same value

Dr.Girija Narasimhan

11
ENTITY Integrity CONSTRAINTS

Null is a value, suppose no other value not assign or apply.

Null is not zero (0) or blank (“ “)
Not Null

Entity integrity not enforced

No null value allowed in the primary key

Dr.Girija Narasimhan

12
Referential Integrity
CONSTRAINTS
• Two tables have relationship or association then use foreign key
Why Referential Integrity constraints?
To maintain Consistency among rows of two relationship.

Rule:
Rule 1: Foreign key must match with primary key of the other
relation.
Rule 2: Otherwise, If it is not matching then Foreign key value must
be “NULL”

Dr.Girija Narasimhan

13
Referential Integrity CONSTRAINTS
EMPLOYEE
Foreign key
Department

EMPLOYEE
Repetition in the foreign
key - allowed

Null value allowed
in the foreign key
Dr.Girija Narasimhan

14
EMPLOYEE

Referential Integrity CONSTRAINTS
Department

Not matching any dept_name in
department table.
So Referential integrity not
enforced

Dr.Girija Narasimhan

15
Referential Integrity CONSTRAINTS
Rule 1: Foreign key must match with primary key of the other relation.

CASCADING DELETE

PROHIBIT DELETE

Dr.Girija Narasimhan

16
Referential Integrity CONSTRAINTS

Dr.Girija Narasimhan

17
CASCADING DELETE
If delete the Primary key table record, automatically the foreign key referencing
table record information also deleted.
For example: Suppose if I delete deptno 20 in DEPT table (master /parent),
automatically in the EMP table empno 6666 and Empno 7329 also deleted
because both are referencing deptno 20.

Dr.Girija Narasimhan

18
PROHIBIT DELETE
Before deleting primary key record, first delete all the foreign key associated
records in referencing table or child table.
For example: First delete EMP table empno 6666 and Empno 7329 and
then delete DEPT table deptno 20

Dr.Girija Narasimhan

19
Rule 2: Otherwise, If it is not matching then Foreign key value must be “NULL”
Place a null value in the Foreign key.
When?
Suppose I want to remove deptno 20 from DEPT TABLE, but I want to retain
or keep the employee 6666 and 7329 in the EMP table , then in the
foreign key attribute DEPTNO column in EMP table instead of 20 I will put
“Null” in both the record 6666 and 7329.

Dr.Girija Narasimhan

20
Mapping ER diagrams to Relations

Why?
Transform Conceptual model to Relational model

Entity type
Regular

Week entity type
Create a new relation

Composite

Binary Relations

Unary Relation

1-1 relation type
1-N relation type
M-N relation type

Multivalued

Dr.Girija Narasimhan

21
Mapping ER diagrams to Relations
Entity type
Regular

Dr.Girija Narasimhan

22
Mapping ER diagrams to Relations
Entity type

Dr.Girija Narasimhan

Composite

23
Mapping ER diagrams to Relations
Entity type

Dr.Girija Narasimhan

Multi valued

24
Mapping Weak Entities

weak entity type does not have an independent existence, but exists only through an
identifying relationship with another entity type called the owner or strong entity.

Dr.Girija Narasimhan

25
Mapping 1-1 Binary Relationship Type
Employee must assign
by only one
Employee may manage one or may
department.
not manage any department

One and only One (Mandatory One)

Zero or One (Optional One)

Using foreign key

Dr.Girija Narasimhan

26
Mapping 1-N Binary Relationship Type

Department have one
or more employee

One or More (Mandatory One)

Employee must work only
one department.

One and only One (Mandatory One)

Dr.Girija Narasimhan

27
Mapping M-N Binary Relationship Type

Employee join one
or more project

Project has one
more employee

One or More (Mandatory One)

One or More (Mandatory One)

Dr.Girija Narasimhan

28
Mapping Unary Relation Type
one employee appointed
as supervisor

Dr.Girija Narasimhan

29

More Related Content

What's hot

Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
Slideshare
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
Jafar Nesargi
 

What's hot (20)

Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
Unit 1 DBMS
Unit 1 DBMSUnit 1 DBMS
Unit 1 DBMS
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
Entity (types, attibute types)
Entity (types, attibute types)Entity (types, attibute types)
Entity (types, attibute types)
 
Relational algebra-and-relational-calculus
Relational algebra-and-relational-calculusRelational algebra-and-relational-calculus
Relational algebra-and-relational-calculus
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
Dbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational ModelDbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational Model
 
joins in database
 joins in database joins in database
joins in database
 
Sql group functions
Sql group functionsSql group functions
Sql group functions
 
Aggregating Data Using Group Functions
Aggregating Data Using Group FunctionsAggregating Data Using Group Functions
Aggregating Data Using Group Functions
 
Dbms keys
Dbms keysDbms keys
Dbms keys
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Database Keys
Database KeysDatabase Keys
Database Keys
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
 
Sql commands
Sql commandsSql commands
Sql commands
 
Unit 4 plsql
Unit 4  plsqlUnit 4  plsql
Unit 4 plsql
 

Viewers also liked

Entity relationship
Entity relationshipEntity relationship
Entity relationship
ronnjemmele
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
Nikhil Deswal
 

Viewers also liked (9)

Relational keys
Relational keysRelational keys
Relational keys
 
Entity relationship
Entity relationshipEntity relationship
Entity relationship
 
Ch 3 E R Model
Ch 3  E R  ModelCh 3  E R  Model
Ch 3 E R Model
 
Agile needs resurgence of visual modeling
Agile needs resurgence of visual modelingAgile needs resurgence of visual modeling
Agile needs resurgence of visual modeling
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
 
Diferencias y semejanzas inv. cualitativa y cuantitativa
Diferencias y semejanzas inv. cualitativa y cuantitativaDiferencias y semejanzas inv. cualitativa y cuantitativa
Diferencias y semejanzas inv. cualitativa y cuantitativa
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging Challenges
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
 

Similar to Database relationship

erdiagramspresentation-150826044953-lva1-app6891.pdf
erdiagramspresentation-150826044953-lva1-app6891.pdferdiagramspresentation-150826044953-lva1-app6891.pdf
erdiagramspresentation-150826044953-lva1-app6891.pdf
vinayakjadhav94
 
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fivFIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
ShainaBoling829
 

Similar to Database relationship (20)

Special lecture er diagram
Special lecture er diagramSpecial lecture er diagram
Special lecture er diagram
 
Desigining of Database - ER Model
Desigining of Database - ER ModelDesigining of Database - ER Model
Desigining of Database - ER Model
 
Entity relationship diagram (erd)
Entity relationship  diagram (erd)Entity relationship  diagram (erd)
Entity relationship diagram (erd)
 
Datamodels.pptx
Datamodels.pptxDatamodels.pptx
Datamodels.pptx
 
DBMS Part-2.pdf
DBMS Part-2.pdfDBMS Part-2.pdf
DBMS Part-2.pdf
 
ER model
ER modelER model
ER model
 
Entity Relationship Diagram2
Entity Relationship Diagram2Entity Relationship Diagram2
Entity Relationship Diagram2
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
 
27 fcs157al3
27 fcs157al327 fcs157al3
27 fcs157al3
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
ER Model in DBMS
ER Model in DBMSER Model in DBMS
ER Model in DBMS
 
ERD with complete knowledge
ERD with complete knowledgeERD with complete knowledge
ERD with complete knowledge
 
erdiagramspresentation-150826044953-lva1-app6891.pdf
erdiagramspresentation-150826044953-lva1-app6891.pdferdiagramspresentation-150826044953-lva1-app6891.pdf
erdiagramspresentation-150826044953-lva1-app6891.pdf
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...Fundamentals of database system  - Data Modeling Using the Entity-Relationshi...
Fundamentals of database system - Data Modeling Using the Entity-Relationshi...
 
chap03Corrected.ppt
chap03Corrected.pptchap03Corrected.ppt
chap03Corrected.ppt
 
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fivFIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
 
DBMS Unit-2_Final.pptx
DBMS Unit-2_Final.pptxDBMS Unit-2_Final.pptx
DBMS Unit-2_Final.pptx
 
Er diagrams presentation
Er diagrams presentationEr diagrams presentation
Er diagrams presentation
 
Er diagrams presentation
Er diagrams presentationEr diagrams presentation
Er diagrams presentation
 

More from Girija Muscut

More from Girija Muscut (20)

Tamil Nalvar
Tamil Nalvar Tamil Nalvar
Tamil Nalvar
 
Visualization using Tableau
Visualization using TableauVisualization using Tableau
Visualization using Tableau
 
Introduction to ml
Introduction to mlIntroduction to ml
Introduction to ml
 
Effective Visualization with Tableau
Effective Visualization with TableauEffective Visualization with Tableau
Effective Visualization with Tableau
 
Guruvayoor song with audio-Udayasthamana puja
Guruvayoor song with audio-Udayasthamana puja Guruvayoor song with audio-Udayasthamana puja
Guruvayoor song with audio-Udayasthamana puja
 
Lakshmi lalli with audio
Lakshmi lalli with audioLakshmi lalli with audio
Lakshmi lalli with audio
 
Bagyada laskhmi purandara dasa
Bagyada laskhmi purandara dasaBagyada laskhmi purandara dasa
Bagyada laskhmi purandara dasa
 
Lakshmi lalli
Lakshmi lalliLakshmi lalli
Lakshmi lalli
 
Amba nee irangaayenil - papanasam sivan song
Amba nee irangaayenil - papanasam sivan songAmba nee irangaayenil - papanasam sivan song
Amba nee irangaayenil - papanasam sivan song
 
Mahalakshmi jagan madha - papanasm sivan tamil song
Mahalakshmi jagan madha  - papanasm sivan tamil songMahalakshmi jagan madha  - papanasm sivan tamil song
Mahalakshmi jagan madha - papanasm sivan tamil song
 
Sowbhagayaha laskhmi varuvai nee tamil song
Sowbhagayaha laskhmi varuvai nee tamil songSowbhagayaha laskhmi varuvai nee tamil song
Sowbhagayaha laskhmi varuvai nee tamil song
 
Bega baro Bega baro Neela Megha Varna-Vadhiraja Theertha
Bega baro Bega baro Neela Megha Varna-Vadhiraja TheerthaBega baro Bega baro Neela Megha Varna-Vadhiraja Theertha
Bega baro Bega baro Neela Megha Varna-Vadhiraja Theertha
 
Rama Nama Bhajan
Rama Nama BhajanRama Nama Bhajan
Rama Nama Bhajan
 
Saratha devi song 1
Saratha devi song 1Saratha devi song 1
Saratha devi song 1
 
Saraswathi bhajan 1 with tamil meaning
Saraswathi bhajan 1 with tamil meaningSaraswathi bhajan 1 with tamil meaning
Saraswathi bhajan 1 with tamil meaning
 
Aneyu karadare -Purandara Dasar.
Aneyu karadare -Purandara Dasar.Aneyu karadare -Purandara Dasar.
Aneyu karadare -Purandara Dasar.
 
Maithriam Bhajatha with tamil meaning (lyrics)
Maithriam Bhajatha with tamil meaning (lyrics)Maithriam Bhajatha with tamil meaning (lyrics)
Maithriam Bhajatha with tamil meaning (lyrics)
 
Unit 4 scd2-exercise 1-solution
Unit 4 scd2-exercise 1-solutionUnit 4 scd2-exercise 1-solution
Unit 4 scd2-exercise 1-solution
 
Unit 2 - Slowly Changing Dimension Type 1 (SCD1) (insert)
Unit 2  - Slowly Changing Dimension Type 1 (SCD1) (insert)Unit 2  - Slowly Changing Dimension Type 1 (SCD1) (insert)
Unit 2 - Slowly Changing Dimension Type 1 (SCD1) (insert)
 
Slowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and update
Slowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and updateSlowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and update
Slowly Changing Dimension Type 1 (SCD 1) exercise 2 solution insert and update
 

Recently uploaded

Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Database relationship

  • 1. CHAPTER 3 Degree of relationship Degree of relationship refers to the number of participating entities in a relationship. Dr.Girija Narasimhan 1
  • 2. Unary Relationship Subjects may be prerequisites for other subjects. Dr.Girija Narasimhan 2
  • 3. M:N unary relationship: A Subject may have many other Subjects as prerequisites and each Subject may be a prerequisite to many other Subjects 1:M unary relationship: An Employee may manage many Employees, but an Employee is managed by only one Employee 1:1 unary relationship: A Person may be married to only one Person. Dr.Girija Narasimhan 3
  • 4. Binary Relationship If there are two entities involved in relationship then it is referred to as binary relationship. Dr.Girija Narasimhan 4
  • 5. Ternary Relationship If there are three entities involved then it is called as ternary relationship and so on. The University might need to record which teachers taught which subjects in which courses. Dr.Girija Narasimhan 5
  • 6. The cardinality of a relationship is the number of instances of entity B that can be associated with entity A. There is a minimum cardinality and a maximum cardinality for each relationship, with an unspecified maximum cardinality being shown as N. Cardinality limits are usually derived from the organizations policies or external constraints. At the University, each Teacher can teach an unspecified maximum number of subjects as long as his/her weekly hours do not exceed 24 (this is an external constraint set by an industrial award). Teachers may teach 0 subjects if they are involved in non teaching projects. Therefore, the cardinality limits for TEACHER are (O,N). Dr.Girija Narasimhan The University's policies state that each Subject is taught by only one teacher, but it is possible to have Subjects that have not yet been assigned a teacher. Therefore, the cardinality limits for SUBJECT are (0,1). 6
  • 7. Relation Relation schema Employee Table Relation (R ) Attributes (A1,A2…An) Employee (Emp_id,ename,Salary) Foreign key Primary key or identifier Employee (Emp_id,ename,Salary) Employee (Emp_id,ename,Salary,dept_name) Foreign key Composite key Department(dept_name,ename,Salary) Over_time (emp_id, dept_name,No_of_hour) Composite key Dr.Girija Narasimhan 7
  • 9. DOMAIN CONSTRAINTS Domain_name Meaning Data type Age Years of the person Phone_no Conduct number Mark size number 3 number Scored by Student in Exam number Dr.Girija Narasimhan 8 3 Allowable value or range <=110 Must be 8 digit and <99999999 and >90000000 >=0 and <=100 9
  • 10. ENTITY Integrity CONSTRAINTS Every relation must have primary key Every primary key attribute is non- null and unique Unique means, value of the primary key must be different not be same. Null is a value, suppose no other value not assign or apply. Null is not zero (0) or blank (“ “) Dr.Girija Narasimhan 10
  • 11. ENTITY Integrity CONSTRAINTS Not Unique Department Entity integrity not enforced Not Unique Same value Dr.Girija Narasimhan 11
  • 12. ENTITY Integrity CONSTRAINTS Null is a value, suppose no other value not assign or apply. Null is not zero (0) or blank (“ “) Not Null Entity integrity not enforced No null value allowed in the primary key Dr.Girija Narasimhan 12
  • 13. Referential Integrity CONSTRAINTS • Two tables have relationship or association then use foreign key Why Referential Integrity constraints? To maintain Consistency among rows of two relationship. Rule: Rule 1: Foreign key must match with primary key of the other relation. Rule 2: Otherwise, If it is not matching then Foreign key value must be “NULL” Dr.Girija Narasimhan 13
  • 14. Referential Integrity CONSTRAINTS EMPLOYEE Foreign key Department EMPLOYEE Repetition in the foreign key - allowed Null value allowed in the foreign key Dr.Girija Narasimhan 14
  • 15. EMPLOYEE Referential Integrity CONSTRAINTS Department Not matching any dept_name in department table. So Referential integrity not enforced Dr.Girija Narasimhan 15
  • 16. Referential Integrity CONSTRAINTS Rule 1: Foreign key must match with primary key of the other relation. CASCADING DELETE PROHIBIT DELETE Dr.Girija Narasimhan 16
  • 18. CASCADING DELETE If delete the Primary key table record, automatically the foreign key referencing table record information also deleted. For example: Suppose if I delete deptno 20 in DEPT table (master /parent), automatically in the EMP table empno 6666 and Empno 7329 also deleted because both are referencing deptno 20. Dr.Girija Narasimhan 18
  • 19. PROHIBIT DELETE Before deleting primary key record, first delete all the foreign key associated records in referencing table or child table. For example: First delete EMP table empno 6666 and Empno 7329 and then delete DEPT table deptno 20 Dr.Girija Narasimhan 19
  • 20. Rule 2: Otherwise, If it is not matching then Foreign key value must be “NULL” Place a null value in the Foreign key. When? Suppose I want to remove deptno 20 from DEPT TABLE, but I want to retain or keep the employee 6666 and 7329 in the EMP table , then in the foreign key attribute DEPTNO column in EMP table instead of 20 I will put “Null” in both the record 6666 and 7329. Dr.Girija Narasimhan 20
  • 21. Mapping ER diagrams to Relations Why? Transform Conceptual model to Relational model Entity type Regular Week entity type Create a new relation Composite Binary Relations Unary Relation 1-1 relation type 1-N relation type M-N relation type Multivalued Dr.Girija Narasimhan 21
  • 22. Mapping ER diagrams to Relations Entity type Regular Dr.Girija Narasimhan 22
  • 23. Mapping ER diagrams to Relations Entity type Dr.Girija Narasimhan Composite 23
  • 24. Mapping ER diagrams to Relations Entity type Dr.Girija Narasimhan Multi valued 24
  • 25. Mapping Weak Entities weak entity type does not have an independent existence, but exists only through an identifying relationship with another entity type called the owner or strong entity. Dr.Girija Narasimhan 25
  • 26. Mapping 1-1 Binary Relationship Type Employee must assign by only one Employee may manage one or may department. not manage any department One and only One (Mandatory One) Zero or One (Optional One) Using foreign key Dr.Girija Narasimhan 26
  • 27. Mapping 1-N Binary Relationship Type Department have one or more employee One or More (Mandatory One) Employee must work only one department. One and only One (Mandatory One) Dr.Girija Narasimhan 27
  • 28. Mapping M-N Binary Relationship Type Employee join one or more project Project has one more employee One or More (Mandatory One) One or More (Mandatory One) Dr.Girija Narasimhan 28
  • 29. Mapping Unary Relation Type one employee appointed as supervisor Dr.Girija Narasimhan 29