Lecture Database management systems Chapter 2 Entity relationship model. This chapter includes contents Introduction, overview of database design, ER model basics, symbols used in ER diagram, attribute classification, ER diagram, relationship degree, relationship classification,...
Trang 1Chapter 2
Entity Relationship Model
Trang 2Introduction
Modeling databases using a graphical
technique is proposed so that humans can relate to easily
ER Model is based on a perception of a real world that consists of collection of basic objects called entities and
relationships among these objects
Trang 3Overview of Database Design
Conceptual design: ( ER Model is used at this stage )
A database “schema” in the ER Model can be represented pictorially (ER diagrams)
The next step in DB design is the actual implementation of the database, using a commercial DBMS
By using the DBMS, conceptual design from high-level data model will be transformed into the implementation data model
Trang 4COMPANY example
The COMPANY database keeps track of company’s employee, departments, and
projects
Suppose that after the requirement
collection and analysis phase, the database designers provide the following
description:
Trang 6COMPANY example
We store each EMPLOYEE’s name 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 the employee
Trang 7◦ Ex:
A particular person, for example Dr Alain is an entity
A particular department, for example CSE faculty
A particular place, for example HCM city can be an entity
Trang 8ER Model Basics
Entity type or entity set: collection of similar entities
◦ Ex:
All students in CSE, say STUDENT
All courses in CSE, say COURSE
An entity may belong to more than one entity type
◦ Ex: The same person is a LECTURER at one instance and STUDENT at another instance
Trang 9ER Model Basics
Relationship: associations among two or more entities
Ex:
◦ An Dang works in Pharmacy department
◦ Teaches is the relationship type between LECTURER and STUDENT
Trang 10Symbols Used in ER Diagram
Entity sets
AttributesRelationships
Trang 11ER Model Basics
Attributes: properties of entity
Ex: Roll number, name, and grade are the attributes of STUDENT
Trang 12Attribute classification
1
Trang 16Attribute classification
Composite Attribute
Trang 17ER Diagram
Trang 18Key attribute
An important constrain on the entities of
an entity type is the KEY on attributes
An attribute of an entity type for which
each entity must have a unique value is called a key attribute of the entity type
For example, SSN of EMPLOYEE
Each key is underlined
Trang 19Relationship degree
Unary Relationship (recursive
relationship):
◦ In the unary relationship the number of
associated entity is one An entity related to itself is known as recursive relationship
Trang 23Relationship Classification
One-to-Many Relationship Type:
◦ The relationship that associates one entity to more than one entity is called one-to-many
Trang 24Relationship Classification
One-to-One Relationship Type:
◦ a special case of one-to-many relationship
◦ True one-to-one relationship is rare
◦ Symbol:
◦ Ex: The relationship between the President and the country is an example of one-to-one relationship
PRESIDENT COUNTRY
Trang 25Relationship Classification
Many-to-Many Relationship Type
◦ Ex: The relationship between students and courses
◦ Symbol:
Trang 26Relationship Classification
Many-to-One Relationship Type
◦ Ex: The relationship between EMPLOYEE and DEPARTMENT is an example of many- to-one relationship There may be many
EMPLOYEES working in one
DEPARTMENT
Trang 27Relationship Classification
Trang 28Reducing ER Diagram to Tables
Mapping Entities:
◦ Regular entities
Entity name = Name of the relation or table
Attributes of ER diagram=Column name of the
table
Trang 29Reducing ER Diagram to Tables
Mapping Composite Attribute:
CUSTOMER (Customer-ID, Customer name,
Street, City, State, Zip)
Trang 30Reducing ER Diagram to Tables
Mapping Multivalued Attribute:
EMPLOYEE (Employee-ID, Name, Address)
EMPLOYEE-SKILL (Employee-ID, Skill)
Trang 31Reducing ER Diagram to Tables
Mapping one-to-Many Relationship:
EMPLOYEE (Customer-ID, Name, Address)
ORDER (Order-ID, Order-Date, Customer-ID)
Trang 32Reducing ER Diagram to Tables
Mapping one-to-Many Relationship:
EMPLOYEE (Customer-ID, Name, Address)
ORDER (Order-ID, Order-Date, Customer-ID)
Trang 33Reducing ER Diagram to Tables
Mapping Many-to-Many Relationship:
EMPLOYEE(Customer-ID, Name, Other attributes)
SHIPMENT(Shipment-No, Customer-ID, Vendor-ID, Date Amount)
ORDER (Vendor-ID, Address, Other Attributes)