Chapter3-ERD2

advertisement
ER Diagrams






Diagrammatic representation of a database schema modeled in the ER model
The most common way to represent the E-R constructs is by using a diagram
There is a variety of notations for E-R Diagrams. Most of the differences concern how
relationships are specified and how attributes are shown.
In almost all variations, entities are depicted as rectangles with either pointed or rounded
corners. The entity name appears inside.
Relationships can be displayed as diamonds or can be simply line segments between two
entities.
For Relationships, need to convey: Relationship name, degree, cardinality, optionally (minimal
cardinality)
Summary of ER Notations
Prepared by: Dr. amjad Mahmood
4.16
ER Diagram Examples
Examples 1
Consider a typical university or college environment:
Possible entities in a university related to courses:
Student
Course
Professor
Section
Room
Relationship between entities:
Entity–1
Professor
Section
Section
Course
Relationships
Teaches
Contains
Requires
Generates
Entity -2
Section
Student
Room
Section
ERD based on above information
Course
Professo
r
1
teaches
1
generate
s
M
M
Section
M
N
contain
s
Studen
t
M
requires
1
Room
Prepared by: Dr. amjad Mahmood
4.17
Example 2

Requirements of the Company (oversimplified for illustrative purposes)
 The company is organized into DEPARTMENTs. Each department has a name,
number and an employee who manages the department. We keep track of the start
date of the department manager.
 Each department controls a number of PROJECTs. Each project has a name, number
and is located at a single location.
 We store each EMPLOYEE’s social security number, address, salary, sex, and
birthdate. Each employee works for one department but may work on several projects.
We keep track of the number of hours per week that an employee currently works on
each project. We also keep track of the direct supervisor of each employee.
 Each employee may have a number of DEPENDENTs. For each dependent, we keep
track of their name, sex, birthdate, and relationship to employee.
Prepared by: Dr. amjad Mahmood
4.18
Alternative (min, max) notation for relationship structural constraints






Specified on each participation of an entity type E in a relationship type R
Specifies that each entity e in E participates in at least min and at most max relationship
instances in R
Default(no constraint): min=0, max=n
Must have minmax, min0, max 1
Derived from the knowledge of mini-world constraints
Examples:
– A department has exactly one manager and an employee can manage at most one
department.
 Specify (0,1) for participation of EMPLOYEE in MANAGES
 Specify (1,1) for participation of DEPARTMENT in MANAGES
– An employee can work for exactly one department but a department can have any
number of employees.
 Specify (1,1) for participation of EMPLOYEE in WORKS_FOR
 Specify (0,n) for participation of DEPARTMENT in WORKS_FOR
Prepared by: Dr. amjad Mahmood
4.19
Example 3
A Bank’s database
Prepared by: Dr. amjad Mahmood
4.20
Exercise: An Example Scenario
We are to design an ER diagram for a University Student Registration System. The university has
many colleges and each college has one or more departments. Each college has an abbreviated
name (unique), full name and location of its main office and has a dean. The department also has an
abbreviated name (unique), full name, and many locations. Each department has a chairman. We
want to keep track of the start date for a dean and chairman. Each department offers different courses
every semester of a year. A student must enroll in a department however there may be many students
in each department. We store each student’s ID, name, address, and telephone number. Each course
has a unique code, title, credit and a list of pre-requisites. A student can register for one or more
courses and the same course can be taken by many students.
There are many teachers in each department who teach one or more sections of one or more courses
in each semester. We store each teacher’s CPR number, name, office number, and telephone
number. Every student has a teacher as his/her advisor and a teacher may advise many students.
Prepared by: Dr. amjad Mahmood
4.21
Download