ER Diagram Reduction to
Relation Schemas
a) Rectangles in ER diagram are entity sets
b) Relation name is the name of the entity set
c) Attributes are the same as in the entity set
d) PK is the PK of the entity set
i) MUST be underlined in relation schema
a) Relation name is the name of the entity set
b) Composite attributes
i) Keep the inner attributes
ii) Do NOT create an attribute for the composite attribute itself
c) Multi-valued attributes
i) Create an additional relation schema that has attributes consisting of
(1) PK of the entity set that contains the multi-valued attribute
(2) attribute that was multi-valued
ii) The PK of the new relation is ALL the attributes
* Because time_slot relation only contains a single attribute which is its own PK, the two relations can be combined to:
a) Rectangles connected to identifying relationships (double-diamonds) are weak entity sets
i) Discriminator is the set of attributes that are underlined with dashes
b) Name of relation is the name of the entity set
c) PK is made up of
i) PK of the strong identifying entity set
ii) Discriminator of the weak entity set
d) Other attributes as they appear in the weak entity set
a) Diamonds in ER diagram are relationship sets
b) Name of relation is the name of the relationship entity set
c) Attributes are the PKs of the two participating entity sets
d) Rename attributes that have the same name
course_dept |
( course_id, dept_name) |
inst_dept |
( id, dept_name) |
stud_dept |
( id, dept_name) |
advisor |
( inst_id, stud_id ) |
teaches |
( id, course_id, sec_id, semester, year ) |
takes |
( id, course_id, sec_id, semester, year, grade ) |
sec_course |
(course_id, sec_id, semester, year ) |
prereq |
( course_id, prereq_id ) |
sec_class |
( building, room_number ) |
sec_time_slot |
(course_id, sec_id, semester, year, time_slot_id ) |
a) Determine cardinality of each of the relationship relations
Card |
Relation |
Attributes |
M:1 |
course_dept |
( course_id, dept_name) |
M:1 |
inst_dept |
( id, dept_name) |
M:1 |
stud_dept |
( id, dept_name) |
1:M |
advisor |
( inst_id, stud_id ) |
M:M |
teaches |
( id, course_id, sec_id, semester, year ) |
M:M |
takes |
( id, course_id, sec_id, semester, year, grade ) |
M:1 |
sec_course |
( course_id, sec_id, semester, year ) |
M:M |
prereq |
( course_id, prereq_id ) |
M:1 |
sec_class |
(sec_id, semester, year, building, room_number ) |
M:1 |
sec_time_slot |
( course_id, sec_id, semester, year, time_slot_id ) |
a) Find all relationship schemas that are 1:1 or 1:M or M:1
b) Prepare to remove redundant relationship schemas by adding PK attributes of the ONE side as FK attributes to the MANY side
Card |
Relation |
Attributes |
Replace Using FK ? |
M:1 |
course_dept |
( course_id, dept_name) |
course->dept_name |
M:1 |
inst_dept |
( id, dept_name) |
instructor->dept_name |
M:1 |
stud_dept |
( id, dept_name) |
student->dept_name |
M:1 |
sec_class |
( building, room_number ) |
section->building,room_number |
M:1 |
sec_time_slot |
( time_slot_id ) |
section->time_slot_id |
M:1 |
sec_course |
(course_id, sec_id, semester, year ) |
from weak entity – just remove |
1:M |
advisor |
( inst_id, stud_id ) |
keeping |
M:M |
teaches |
( id, course_id, sec_id, semester, year ) |
|
M:M |
takes |
( id, course_id, sec_id, semester, year, grade ) |
|
M:M |
prereq |
( course_id, prereq_id ) |
|
section( course_id, sec_id, semester, year, building, room_number)
a) Define all FKs on relation schemas
b) Delete redundant relationship schemas and define FKs on remaining schemas