ER-to-Relational Data Model
9.1 An Entity-Relationship (ER) Diagram
9.2 A Relational Data Schema
| EMPLOYEE |
|
| Fname | Lname | SSN | SupervisorSSN |
|
|
| DEPARTMENT |
|
| Name | NUMBER | MANAGER-SSN | StartDate |
|
|
| DEPENDENT | |
| DEP-LOCATION | |
| WORKS-FOR | |
Comments:
| EMPLOYEE (SupervisorSSN) | → | EMPLOYEE (SSN) |
| DEPARTMENT (MANAGER-SSN) | → | EMPLOYEE (SSN) |
| DEPENDENT (EMPL-SSN) | → | EMPLOYEE (SSN) |
| DEP-LOCATION (DEP-NUMBER) | → | DEPARTMENT (NUMBER) |
| WORKS-FOR (EmployeeSSN) | → | EMPLOYEE (SSN) |
| WORKS-FOR (DeptNumber) | → | DEPARTMENT (NUMBER) |
| unique: DEPARTMENT.NAME | |
create table EMPLOYEE{
Fname...
Lname...
SSN... primary key
SupervisorSSN... reference EMPLOYEE(SSN)
}
create table DEPARTMENT{
NAME...
NUMBER... primary key
MANAGER-SSN... references EMPLOYEE(SSN)
StartDate
}
create table DEPENDENT{
Relationship...
EMPL-SSN... references EMPLOYEE(SSN)
Name ...
primary key(EMPL-SSN,Name)
}
create table DEP-LOCATION{
Location... primary key
DEPNUMBER... references DEPARTMENT(Number)
}
create table WORKS-FOR{
EmployeeSSN... references EMPLOYEE(SSN)
DeptNumber... references DEPARTMENT(Number)
}
9.3 The Mapping
(Strong) Entity Type into Relation
- Include the simple attributes
- Include the simple components of the composite attributes
- Identify the primary keys
- Don’t include: non-simple components of composite attributes, foreign keys, derived attributes, relational attributes
Binary 1:1 Relationship Types into Foreign Keys
- Include as foreign keys, in the relation of one entity type, the primary keys of the other entity type
- Include also the simple attributes of the relationship type
- If possible, the first entity type should have total participation in the relationship (to save memory!)
Binary 1:N Relationship Types into Foreign Keys
- Add as foreign keys, to the relation of the entity type at the N side, the primary keys of the entity type at the 1 side
(don’t duplicate records!)
- Include also the simple attributes of the relationship type
Binary M:N Relationship Type into Relation
- We don’t want to duplicate records!
- Set as foreign keys the primary keys of the participating entity types
- Include the simple attributes of the relationship type
N-Ary Relationship Type
Similar to binary M:N relationship type
Multivalued Attribute into Relation
- Include the given attribute
- Include as foreign keys the primary attributes of the entity/relationship type owning the multivalued attribute
- Keys not designated within primary keys are to be mentioned as such in side comments
Resembles the treatment of a relationship type.
Weak Entity+Relationship Types into Relation
- Include simple attributes
- Add the owner’s primary key attributes, as foreign key attributes
- Declare into a primary key the partial keys of the weak entity type combined with those imported from the owner
Reference: Ch. 7.1 in textbook.
9.4 Assignment #5
Due: Mo, Feb 16
Problem 7.4 from textbook (page 204 4th ed; 237 5th ed).
Notes
- If you submit your homework electronically, use the departmental submit utility: submit XXX lab5
filename. XXX represents ‘c670aa’ for students of the 3:30 section, and ‘c670ab’ for students of the 5:30
section.
- Files are restricted to 1,048,576 bytes
- The submit program issues error messages to the student’s CSE email account
Q&A