Entity-Relationship (Er) Modeling
Entity-Relationship (Er) Modeling
(ER) MODELING
Definition
is a high-level conceptual data model diagram. ER modeling helps you to analyze data
requirements systematically to produce a well-designed database.
The Entity-Relation model represents real-world entities and the relationship between
them.
■ Examples:
– An employee is a strong entity but the dependents of the employee
could be weak entities
– An account in a bank is a strong entity but a transaction could be a
week entity
Types of Attributes
■ Simple (or atomic) attribute is a one which cannot be divided into smaller
parts.
– Examples: SSN, GPA, Salary, Sex.
Address
FN LN DOB
Person
Example of different attributes
To have a simple example of a person with attributes
» Child: Bob
» Child: Carol
» FN: Alice
» LN: Xie
» DOB: 1980-01-01
» Address.Number: 100
» Address.Street: Mercer
» Age: Current Date minus DOB specified in years (rounded down)
Example: ER diagram of the CAR
entity type
Binary relationship
SUPERVISE
EMPLOYEE
N 1
EMPLOYEE WORKS-FOR COMPANY
1 1 MANAGER
DEPARTMENT HAS
M N PROJECT
EMPLOYEE WORKS-ON
m n
Student takes Course
grade
E-R Diagram with Relationships
Example
College Registration System:
• College Courses: contain course code, title and credits.
• Course offering: contain course code, year, semester, section number,
teacher, time and class room.
• Student : contain student id, student name, stream.
• Teacher: contain teacher ID, teacher name, faculty, title.
In addition, the enrollment of student in any courses and mark that
display to them must be appropriately model.
Course
Title Credit
code
Course
Teacher ID
Student
Binary relationship
1. University
2. Faculty
3. School
4. Program
5. Course
6. Lecturer
7. Student
Step 2 - Find Relationships
Step 3 - Draw rough ERD
Step 4 - Fill in The Cardinality
■ Each faculty is divided into several schools
■ Each school offers numerous programs
■ Each program contains many courses
■ Each school employs many lecturers
■ Lecturers can teach many courses
■ Lecturers can teach the same course many times
■ Courses can be taught by more than one lecturer
■ A student is enrolled in only one program
■ Students can be enrolled in many courses at the same time
■ Courses have many students enrolled
DRAW FULLY ATTRIBUTES ERD - Homework
Company Database – Example
Requirements:
■ The company is organized into departments. Each department has a unique name, a
unique number, and a particular employee who manages the department. We keep track
of the start date when that employee began managing the department. A department
may have several locations.
■ A department controls a number of projects, each of which has a unique name, a unique
number, and a single location.
■ The database will store each employee’s name, Social Security number, address, salary,
sex (gender), and birth date. An employee is assigned to on department, but may work on
several projects, which are not necessarily controlled by the same department. It is
required to keep track of the current number of hours per week that an employee works
on each project, as well as the direct supervisor of each employee (who is another
employee).
■ The database will keep track of the dependents of each employee for insurance
purposes, including each dependent’s first name, sex, birth date, and relationship to the
employee
IdentifingEntities
1. An entity type DEPARTMENT with attributes Name, Number, Locations, Manager, and
Manager_start_date. Locations is the only multivalued attribute. We can specify that both Name and
Number are (separate) key attributes because each was specified to be unique.
2. An entity type PROJECT with attributes Name, Number, Location, and Controlling_department. Both
Name and Number are (separate) key attributes.
3. An entity type EMPLOYEE with attributes Name, Ssn, Sex, Address, Salary, Birth_date, Department,
and Supervisor. Both Name and Address may be composite attributes; however, this was not specified in
the requirements. We must go back to the users to see if any of them will refer to the individual
components of Name—First_name, Middle_initial, Last_name—or of Address. In our example, Name is
modeled as a composite attribute, whereas Address is not, presumably after consultation with the users.
4. An entity type DEPENDENT with attributes Employee, Dependent_name, Sex, Birth_date, and
Relationship (to the employee).
Company Database – Solution