0% found this document useful (0 votes)
22 views25 pages

Lecture 10

The document discusses mapping relationships between entities in a database from an E-R diagram to tables in a relational database management system. It covers different types of relationships like one-to-one, one-to-many, many-to-many and discusses how to represent them using primary and foreign keys. It also discusses unary relationships, supertype/subtype relationships and relational algebra operations.

Uploaded by

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

Lecture 10

The document discusses mapping relationships between entities in a database from an E-R diagram to tables in a relational database management system. It covers different types of relationships like one-to-one, one-to-many, many-to-many and discusses how to represent them using primary and foreign keys. It also discusses unary relationships, supertype/subtype relationships and relational algebra operations.

Uploaded by

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

Database

Management
System
Mapping Relationships
Relationships are mapped
according to their degree and
cardinalities
Starting from binary relationships
Binary Relationships
Cardinality: one to many
The PK of the relation against
many side ET contains the PK of
the relation for ET on one side as
FK
One to Many Example

EMP PROJ

EMP(empId, empName, projId)


PROJ(projId, projName, projDur, projCost)
Minimum Cardinality

Minimum cardinality on one side


needs special attention
If optional, define FK as normal
If compulsory, make FK not null
Minimum Cardinality
Example
empId empName deptId

EMP DEPT

empAddr deptName

EMP(empId, empName, empAddr)


DEPT(deptId, deptName)
Many to Many Relationship
A third table is created for the
relationship, sometimes also called
associative entity type
Generally, the PKs of the
participating ETs are used as PK of
the third table
Many to Many
Relationship Example
bkId bkTitle stId sName

BOOK STD

bkAuth sFname

STD(stId, sName, sFname)


BOOK(bkId, bkTitle, bkAuth)
TARNS(bkId, stId)
bkId bkTitle isDate stId sName

BOOK STD

rtDate sFname
bkAuth
bkId stId

STD(stId, sName, sFname)


BOOK(bkId, bkTitle, bkAuth)
TARNS(bkId, stId, isDate, rtDate)
Binary one to one
A special form of one to many
relationship
PK of one ET has to be included in
the other as FK.
Normally PK of compulsory side is
included in the optional side
One to One Example
stId stName hDur

STD HOBBY
hName
stAddr

STD(stId, stName, stAddr)


HOBBY(hName, hDur, stId)
Unary Relationships
Unary one to many introduces
the PK of same ET as FK
Many to many unary requires
creation of another relation with a
composite PK
Unary Example
empName empId

EMP

eQual
manages

EMP(empId, empName, eQual, empId)


Unary Example
empName empId

EMP

eQual
manages

EMP(empId, empName, eQual, mgrId)


Unary Example
iName itemNo

ITEM

uCost

has Qty

ITEM(itemNo, iName, uCost)


COMPONENT(itemNo, CompNo, Qty)
Super/Subtype Relationship
Separate relations are created for
each of the supertype and subtypes
Assign relevant attributes
Primary key of the supertype is
included in all relations, that work
for both the identity and the link
Super/Subtype example
empName empAddr
empId e-Type
EMP

“H” “C”
“S”

HOURLY SALARIED CONSULTANT


Summary of Mapping E-R
Diagram to Relational DM
DATA
MANIPULATION
LANGUAGES
Relational Algebra
Relational algebra operations
work on one or more relations to
define another relation leaving the
original intact.
Relational Algebra
Both operands and results are
relations, so output from one
operation can become input to
another operation.
Relational Algebra
Allows expressions to be nested,
just as in arithmetic. This property
is called closure.
Relational Algebra
5 basic operations in relational
algebra: Selection, Projection,
Cartesian product, Union, and
Set Difference.
Relational Algebra
These perform most of the data
retrieval operations needed.
Also have Join, Intersection, and
Division operations, which can be
expressed in terms of 5 basic
operations.

You might also like