0% found this document useful (0 votes)
31 views35 pages

Entity-Relationship (Er) Modeling

database lab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views35 pages

Entity-Relationship (Er) Modeling

database lab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

ENTITY-RELATIONSHIP

(ER) MODELING
Definition

■ ENTITY RELATIONAL (ER) MODEL

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.

ER model consists of three basic constructs: entities, attributes and relationships.


Components
Entity and Entity Set
■ Two types of entities:
– Strong entity: can exist independently (or can uniquely identify itself)
– Weak entity: existence depends on the existence of other (strong) entity
or entities

■ 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.

■ Composite attribute is an attribute which can be divided into smaller


subparts, these subparts represent more basic attributes with independent
meanings of their own.
– Examples: Name: First_Name, Middle_Name, Last_Name
– Address: Street_Address, City, State, Zip code
An Example of A Composite Attribute

Address

Street-Address City State Post Code

House No. Street Name


Types of Attributes
■ A single-valued attribute is a one which has one (single) value for
a particular entity.
– Example: Age, BirthDate

■ A multi-valued attribute is a one which may have one or more


values for the same entity.
– Authors of Books
– Phone Number
Types of Attributes

■ A stored attribute is a one whose value is explicitly stored in the database.


– e.g. name, birth-date.

■ Derived-attributes: whose values are computed from other attributes.


– Age from Birthdate
– Annual Salary from Monthly Salary
– NoOfEmployees ==> Count number of employees in the Employee
table.
■ An entity may have a set of zero or more attributes, which are some properties
■ Attributes of an entity are written in ellipses (for now solid lines) connected to the
entity
– Example: FN: “First Name.” LN: “Last Name.” DOB: “Date of Birth.”

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

Professor advises Student

SSN Name Age SSN Name Age


Recursive Relationship

■ The SUPERVISION relationship type relates an employee to a supervisor, where both


employee and supervisor entities are members of the same EMPLOYEE entity set
Recursive Relationship - Example

SUPERVISE

EMPLOYEE

SSN Name Age


Constraints on Relationships
■ Constraints on Relationship Types
– Cardinality Ratio (specifies maximum participation)
■ One-to-one (1:1)
■ One-to-many (1:N) or Many-to-one (N:1)
■ Many-to-many (M:N)

– Existence Dependency Constraint (specifies minimum


participation) (also called participation constraint)
■ zero (optional participation, not existence-dependent)
■ one or more (mandatory participation, existence-dependent
One-to-many (1:N) or Many-to-one (N:1)

N 1
EMPLOYEE WORKS-FOR COMPANY

An employee works for one company, and


a company has many employees working
for it.
One-to-one (1:1)

1 1 MANAGER
DEPARTMENT HAS

A department has one manager and a


manager manages one department.
Many-to-many (M:N)

M N PROJECT
EMPLOYEE WORKS-ON

An employee works on many projects, and


a project has many employees working on
it.
Attribute of Relationship
Where to keep the grade information?

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

Faculty Name Title

Teacher ID

Stream Name Student ID

Student
Binary relationship

Figure 4: College ER diagrams


ERD Notations
Example
As a database developer, you got a new project to design a database system for a
university to organize the students, courses, and teachers information. You conducted a
meeting with the university dean to gather the requirements. The University contains
many Faculties. Each faculty has a unique name, address (cannot be null) and phone
number (may be more than one). The Faculties in turn are divided into several Schools.
School has school name and number of students, and each school offers numerous
programs and each program contains many courses. Lecturers can teach many
different courses and even the same course numerous times. Courses can also be
taught by many lecturers. A student is enrolled in only one program but a program can
contain many students. Students can be enrolled in many courses at the same time and
the courses have many students enrolled.
Step 1 - Identify Entities

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy