Docsity

Translation of Entity-Relationship Model to Relational Schema in Database Design, Slides of Introduction to Database Management Systems

Toggle sidebar
bg1
1
Relational Database Design
Part II
CPS 116
Introduction to Database Systems
2
Announcements
Homework #1 due in 7 days (Thursday, Sept. 9)
Details of the course project and presentations will
be available next Tuesday
Discussion session next week: Homework #1 Q&A
Vote on meeting time in this lecture
3
E/R model: review
Entity sets
Keys
Weak entity sets
Relationship sets
Attributes on relationships
Multiplicity
Roles
Binary versus N-ary relationships
•Modeling N-ary relationships with weak entity sets and binary
relationships
ISA relationships
4
Database design steps: review
Understand the real-world domain being modeled
Specify it using a database design model (e.g., E/R)
Translate specification to the data model of DBMS
(e.g., relational)
Create DBMS schema
)Next: translating an E/R design to a relational
schema
5
Translating entity sets
An entity set translates directly to a table
Attributes →columns
Key attributes →key columns
Students Courses
CID
title
Enroll
SID
name
grade
Student (SID, name)Course (CID, title)
6
Translating weak entity sets
Remember the “borrowed” key attributes
Watch out for attribute name conflicts
Rooms In Buildings
name
year
number
capacity
In
Seats
number
L/R? Building (building_name, year)
Rooms (building_name, room_number, capacity)
Seats (building_name, room_number, seat_number, left_or_right)
pf3

Partial preview of the text

Download Translation of Entity-Relationship Model to Relational Schema in Database Design and more Slides Introduction to Database Management Systems in PDF only on Docsity!

Relational Database Design

Part II

CPS 116

Introduction to Database Systems

Announcements

™ Homework #1 due in 7 days (Thursday, Sept. 9)

™ Details of the course project and presentations will

be available next Tuesday

™ Discussion session next week: Homework #1 Q&A

ƒ Vote on meeting time in this lecture

3

E/R model: review

™ Entity sets

ƒ Keys

ƒ Weak entity sets

™ Relationship sets

ƒ Attributes on relationships

ƒ Multiplicity

ƒ Roles

ƒ Binary versus N -ary relationships

  • Modeling N -ary relationships with weak entity sets and binary relationships

ƒ ISA relationships

4

Database design steps: review

™ Understand the real-world domain being modeled

™ Specify it using a database design model (e.g., E/R)

™ Translate specification to the data model of DBMS

(e.g., relational)

™ Create DBMS schema

) Next: translating an E/R design to a relational

schema

5

Translating entity sets

™ An entity set translates directly to a table

ƒ Attributes → columns

ƒ Key attributes → key columns

Students Courses CID title

SID Enroll name grade Student ( SID , name ) Course ( CID , title )

6

Translating weak entity sets

™ Remember the “borrowed” key attributes

™ Watch out for attribute name conflicts

Rooms In Buildings name year

number capacity In number Seats L/R? Building^ ( building_name ,^ year ) Rooms ( building_name , room_number , capacity ) Seats ( building_name , room_number , seat_number , left_or_right )

Translating relationship sets

™ A relationship set translates to a table

ƒ Keys of connected entity sets → columns

ƒ Attributes of the relationship set (if any) → columns

ƒ Multiplicity of the relationship set determines the key of

the table

Students Courses CID title

SID Enroll name grade Enroll ( SID , CID , grade )

More examples

Students Enroll Courses TA’s

CID

title

SID

name (^) TID

name Enroll^ ( SID ,^ CID ,^ TID )

Marry ( husband_SSN , wife_SSN )

Persons Marry

husband

wife

SSN

Marry ( husband_SSN , wife_SSN )

9

Translating double diamonds

™ Recall that a double-diamond relationship set connects a

weak entity set to another entity set

™ No need to translate because the relationship is implicit in

the weak entity set’s translation

Rooms In Buildings

name year

number capacity In numberL/R? Seats

RoomInBuilding ( room_building_name , room_number , building_name ) is subsumed by Rooms ( building_name , room_number , capacity )

10

Translating subclasses & ISA (approach 1)

™ Entity-in-all-superclasses approach (“E/R style”)

ƒ An entity is represented in the table for each subclass to which it belongs ƒ A table include only the attributes attached to the corresponding entity set, plus the inherited key Students Courses CID title

SID Enroll name

office GradStudents

ISA (^) Course ( CID , title ) Student ( SID , name ) Enroll ( SID , CID ) GradStudent ( SID , office )

h 444, “Apu”i (^) ∈ h 142, “Bart”i h 444, “D444”i ∈

11

Translating subclasses & ISA (approach 2)

™ Entity-in-most-specific-class approach (“OO style”)

ƒ An entity is only represented in one table (corresponding to the most specific entity set to which the entity belongs) ƒ A table includes the attributes attached to the corresponding entity set, plus all inherited attributes Students Courses

CID

Enroll title

SID

name

office GradStudents

ISA (^) Course ( CID , title ) Student ( SID , name ) Enroll ( SID , CID ) h 444, “Apu”, “D444”i ∈ GradStudent ( SID , name , office )

h 142, “Bart”i ∈

12

Translating subclasses & ISA (approach 3)

™ All-entities-in-one-table approach (“NULL style”)

ƒ One relation for the root entity set, with all attributes found anywhere in the network of subclasses ƒ Use a special NULL value in columns that are not relevant for a particular entity Students Courses

CID

Enroll title

SID

name

office GradStudents

ISA (^) Course ( CID , title ) Student ( SID , name , office ) Enroll ( SID , CID )

h 444, “Apu”, “D444”i (^) ∈ h 142, “Bart”, NULLi