Lecture 2 ERD
Lecture 2 ERD
Conceptual Design
Designing a Database
• Requirement Gathering
• Conceptual Design Conceptual Model
• Entity Relationship Diagram (ERD)
• Logical Design Logical Model
• Relational Schema
• Physical Design Physical Model
• Actual implementation on a DBMS
• Indexes
• Views
• Normalize or de-Normalize
• Security
• Access rights
Conceptual design
Pictorial Form / Flow chart
• Made for client
• Easy to understand
• Inexpensive to change
We will start with Conceptual
design
ER diagram
• An entity relationship diagram (ERD) shows the relationships of entity
sets stored in a database.
• Example:
Student Course
Strong Entity vs Weak Entity
• An entity is strong if it can independently exist
• Representation
Section
Attributes representation in ERD
(Oval)
• Properties of an entity
id
Student
name
Types of an attribute
• Types of attributes
• Key attribute
• Composite attribute
• Derived attribute
• Simple attribute
• Multivalued attribute
Attributes
Month
date
DOB
Age year
CGPA
Hobby
Roll No Student
Complex attribute
Types of keys
Relationship representation in ERD
(Diamond)
Student Enrolls Course
in
Is taught
by
Teacher
Course Student
Enrolls
Cardinality Participation
• One to many (1:N) • Total Participation
• One to one (1:1) • Partial participation
• Many to many (M:N)
Relationship: cardinality
• 1:M
1
M
Faculty Works Department
for
• M:N
N M
Faculty Courses
Teaches
• 1:1
1 1
Faculty Is head Department
of
Relationship: Particitaion
• Total or partial
Department
Faculty works
Faculty Courses
Teaches
• M:N
M N
Faculty Courses
Teaches
• 1:1
1
1
Faculty Is head Department
of
Attributes of relationship
• A relationship can have attributes:
• For example, grade of enrolls
• Its value for each relationship instance describes the grade a student takes
when he is enrolled in a course.
• A value of Grade depends on a particular (Student,Course) combination
Students Course
Enrolls
Grade
Recursive Relationship: Rolenames
• Employee is supervisor of other employees
supervisee
Employee
Supervisor
1 is M
supervisor
of
Identifying relationship
• 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.
• We store each employee’s name, Social Security number,2 address, salary, gender ,
and birth date. An employee is assigned to one department, but may work on
several projects, which are not necessarily controlled by the same department. We
keep track of the current number of hours per week that an employee works on
each project. We also keep track of the direct supervisor of each employee (who is
another employee).
• We want to keep track of the dependents of each employee for insurance
purposes. We keep each dependent’s first name, gender, birth date, and
relationship to the employee.