Relationship Review: Works For Employee Department
Relationship Review: Works For Employee Department
Relationship Review: Works For Employee Department
Each time an attribute of one entity type refers to another entity type, some
relationship exists.
In ER diagrams, these references should be represented as relationships, rather than
attributes.
For example, in the Company database schema, an attribute of employee is the
department they work for, rather than representing this information as an attribute of
the Employee entity type, it should be represented on a diagram as a relationship
between the two entities.
Relationships between entities are represented using a diamond shape.
Relationships are usually given a verb name, which specifies the relationship between
two entities.
If we look at the relationship between Employee and Department, an employee works
for a department, therefore the relationship would be represented
Works for
Employee Department
Supplies
Supplier Project
Part
For example, in the Company schema, each employee has a supervisor, we need to
include the relationship “Supervises”, however a supervisor is also an employee,
therefore the employee entity type participates twice in the relationship, once as an
employee and once as a supervisor, therefore we can specify two roles, employee and
supervisor.
Employee
o Partial:
If only a part of the set of entities participate in a relationship, then it is
called partial participation.
Using the Company example, every employee will not be a manager of
a department, so the participation of an employee in the “Manages”
relationship is partial.
Partial participation is represented by a single line.
For example, lets assume in a library database, we have an entity type Book. For
each book, we keep track of the author, ISBN, and title. The library may own several
copies of the same book, and for each copy, it keeps track of the copy number (a
different copy number for each copy of a given book) and price of each copy.
Has
Book Copy
Because the copy number is only unique for each book (meaning Book 123 may have
copy 1, copy 2, copy 3, and book 456 may also have copy 1, copy 2 and copy 3) and
not for all copies of all books, it cannot be considered unique for each copy.
Therefore because the Copy entity does not have a key attribute, it is considered a
weak entity type, an is identified by being related to the Book entity. The book entity
is the identifying entity, and the relationship is the identifying relationship.
Because a copy cannot exist without the owner (Book) the Copy entity type has a
total participation constraint with respect to the identifying relationship.
The partial key of the Copy entity is Copy Number, for each owner entity Book, the
Copy Number uniquely identifies the copy.
Min-Max Notation
Before we saw that to specify structural constraints (cardinality) we used the M:N
notation.
An alternate notation involves specifying a pair of integers, which are used to specify
the minimum and maximum participation of each entity type in the form of (min,
max)
A minimum participation of 0 indicates partial participation (meaning that there may
be some entities that do not participate in the relationship)
A minimum participation of 1 or more indicates total participation, meaning that each
entity must participate in exactly/at least one-relationship type.
See PowerPoint “ERD_Examples.ppt”, Slide 1 to demonstrate.
Notation Summary
See Slide 2 and Slide 3 of PowerPoint “ERD_Examples.ppt” to demonstrate.
To demonstrate using Min-Max notation, see slide 4.
Examples
University Example – Exercise 3.16
See PowerPoint “ERD_Examples.ppt” Slide 5 to demonstrate.
Consider the following set of requirements for a university database that is used to keep
track of student's transcripts:
The university keeps track of each student's name, student number, social security
number, current address and phone number, permanent address and phone number,
birthdate, sex, class (freshman, graduate), major department, minor department (if
any), degree program (B.A., B.S., ... Ph.D.). Some user applications need to refer to
the city, state, and zip code of the student's permanent address and to the student's last
name. Both social security number and student number are unique for each student.
All students will have at least a major department.
Each department is described by a name, department code, office number, office
phone, and college. Both the name and code have unique values for each department.
Each course has a course name, description, course number, number of credits, level
and offering department. The course number is unique for each course.
Each section has an instructor, semester, year, course, and section number. The
section number distinguishes sections of the same course that are taught during the
same semester/year; its value is an integer (1, 2, 3, ... up to the number of sections
taught during each semester).
A grade report must be generated for each student that lists the section, letter grade,
and numeric grade (0,1,2,3, or 4) for each student and calculates his or her average
GPA.