0% found this document useful (0 votes)
14 views68 pages

Week 7 - ERD-1

Uploaded by

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

Week 7 - ERD-1

Uploaded by

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

Data Modeling Using

Entity-Relationship (ER) Model


Chapter Outline
• Example Database Application (COMPANY)
• ER Model Concepts
– Entities and Attributes
– Entity Types, Value Sets, and Key Attributes
– Relationships and Relationship Types
– Weak Entity Types
– Roles and Attributes in Relationship Types
• ER Diagrams - Notation
• ER Diagram for COMPANY Schema

2
Example COMPANY
Database
• Requirements of the Company
– 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.

3
Example COMPANY Database
(Cont.)

– 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.
Entity

• Entity - Thing which has existence distinguishable from other


objects (things)
 independent existence

 can be concrete or abstract


described by its attributes (set of properties)
 determined by particular value of its attributes

Example
Rama, Raghu
Maker Towers, Hotel Cecil
ER Model Concepts
• Entity

– Entities are specific objects or things in the mini-world that


are represented in the database.
– For example the EMPLOYEE John Smith, the Research
DEPARTMENT, the ProductX PROJECT

• Entity type

– Entities with the same basic attributes are grouped or


typed into an entity type.
– For example, the EMPLOYEE entity type or the PROJECT
entity type.
ER Model Concepts
• Attributes

– Attributes are properties used to describe an entity.

– For example an EMPLOYEE entity may have a Name,


SSN, Address, Sex, BirthDate

– A specific entity will have a value for each of its attributes.


For example a specific employee entity may have
Name='John Smith', SSN='123456789', Address ='731,
Fondren, Houston, TX', Sex='M', BirthDate='09-JAN-55‘

– Each attribute has a value set (or data type) associated


with it – e.g. integer, string, subrange, enumerated type, …
Key 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.

• A key attribute may be composite. For example,


VehicleTagNumber is a key of the CAR entity type with
components (Number, State).

• An entity type may have more than one key. For example,
the CAR entity type may have two keys:
– VehicleIdentificationNumber (popularly called VIN) and
– VehicleTagNumber (Number, State), also known as
license_plate number.
Entity Sets
• An entity set is a set of entities of the same type that
share the same properties.
– Example: set of all persons, companies, trees, holidays

ENTITY SET corresponding to the


ENTITY TYPE CAR
CAR
Registration(RegistrationNumber, State), VehicleID, Make, Model, Year, (Color)

car1
((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red, black))
car2
((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue))
car3
((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue))
.
SUMMARY OF ER-DIAGRAM
NOTATION FOR ER SCHEMAS
Symbol Meaning

ENTITY TYPE

WEAK ENTITY TYPE

RELATIONSHIP TYPE

IDENTIFYING RELATIONSHIP TYPE

ATTRIBUTE

KEY ATTRIBUTE

MULTIVALUED ATTRIBUTE

COMPOSITE ATTRIBUTE

DERIVED ATTRIBUTE

E1 R E2 TOTAL PARTICIPATION OF E2 IN R
1 N
E1 R E2
CARDINALITY RATIO 1:N FOR E 1:E2 IN R
Summary of Symbols Used in
E-R Notation
ER DIAGRAM – Entity Types are:
EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT
Relationship
• A relationship relates two or more distinct entities with a
specific meaning.

• For example, EMPLOYEE John Smith works on the


ProductX PROJECT or EMPLOYEE Franklin Wong
manages the Research DEPARTMENT.
Relationship Type
• Relationships of the same type are grouped or typed into a
relationship type.
• For example, the WORKS_ON relationship type in which
EMPLOYEEs and PROJECTs participate, or the
MANAGES relationship type in which EMPLOYEEs and
DEPARTMENTs participate.

• More than one relationship type can exist with the same
participating entity types.
• For example, MANAGES and WORKS_FOR are distinct
relationships between EMPLOYEE and DEPARTMENT,
but with different meanings and different relationship
instances.
• A relationship set is a class of relationships of the same type,
having common properties
Attributes of Relationship types

• A relationship type can have attributes; for example,


HoursPerWeek of WORKS_ON; its value for each
relationship instance describes the number of hours per
week that an EMPLOYEE works on a PROJECT.
Attribute of a Relationship Type is:
Hours of WORKS_ON
Structural Constraints –
one way to express semantics of relationships
 Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or
M:N
SHOWN BY PLACING APPROPRIATE NUMBER ON THE LINK.
 Participation constraint (on each participating entity type):
total (called existence dependency) or partial.
SHOWN BY DOUBLE LINING THE LINK
NOTE: These are easy to specify for Binary Relationship Types.
The minimum and maximum values of this connectivity is called the cardinality of
the relationship
Participation of an Entity Set in a Relationship
Set
 Total participation (indicated by double line): every entity in the entity set
participates in at least one relationship in the relationship set
 E.g. participation of loan in borrower is total
 every loan must have a customer associated to it via borrower
 Partial participation: some entities may not participate in any relationship in
the relationship set
 E.g. participation of customer in borrower is partial
ER DIAGRAM – Relationship Types are:
WORKS_FOR, MANAGES, WORKS_ON, CONTROLS,
SUPERVISION, DEPENDENTS_OF
Roles
• Entity sets of a relationship need not be distinct
• The labels “manager” and “worker” are called roles; they specify
how employee entities interact via the works-for relationship set.
• Roles are indicated in E-R diagrams by labeling the lines that
connect diamonds to rectangles.
• Role labels are optional, and are used to clarify semantics of the
relationship
Recursive Relationship Type
• Both participants are same entity type in different roles.

• For example, SUPERVISION relationships between


EMPLOYEE (in role of supervisor or boss) and (another)
EMPLOYEE (in role of subordinate or worker).

• In following figure, first role participation labeled with 1 and


second role participation labeled with 2.

• In ER diagram, need to display role names to distinguish


participations.
A RECURSIVE RELATIONSHIP
SUPERVISION
EMPLOYEE SUPERVISION

e1  2
1 r1
e2  2
1
r2
e3  2
1
e4  2 r3
1
e5  1
2 r4
e6  1

2 r5
e7 

r6
Recursive Relationship Type is: SUPERVISION
(participation role names are shown)
Weak Entity

Entities that are distinguished by their relationship to another entity

PF account of an employee
Engineer of a ship

 Weak entity has partial key or discriminator –


 Identify entities related to the same strong entity.

 The primary key = primary key of the strong entity set


+ discriminator.

 Do not have a key of their own


Weak Entity Types
• A weak entity must participate in an identifying relationship type
with an owner or identifying entity type
• Entities are identified by the combination of:
– A partial key of the weak entity type
– The particular entity they are related to in the identifying
entity type
Example:
Suppose that a DEPENDENT entity is identified by
the dependent’s first name and birthdate,
and the specific EMPLOYEE that the dependent is related to.
DEPENDENT is a weak entity type with EMPLOYEE as its
identifying entity type via the identifying relationship type
DEPENDENT_OF
Weak Entity Types
Example:

Suppose that a DEPENDENT entity is identified by the


dependent’s first name and birthdate,
and the specific EMPLOYEE that the dependent is
related to.

DEPENDENT is a weak entity type with EMPLOYEE as


its identifying entity type via the identifying relationship
type DEPENDENT_OF
Weak Entity Type is: DEPENDENT
Identifying Relationship is: DEPENDENTS_OF
These attributes best describe the relationship prescription rather than any
individual entity Doctor, Patient or Medicine.
The identifying relationship is the one which relates the weak entity (dependant) with
the strong entity (Employee) on which it depends.
Id is underlined with a dotted line because it is used to form composite key of
dependent entity along with E#.
Relationships of Higher Degree

 Relationship types of degree 2 are called binary


 Relationship types of degree 3 are called ternary
and of degree n are called n-ary
 In general, an n-ary relationship is not equivalent to
n binary relationships
Example of a ternary
relationship

SUPPLY relationship instance: (s,j,p)


A supplier s supplies part p to project j
Ternary vs Binary Relationship Types

3 binary
relationships

Suppose (s,j), (j,p), and (s,p) participate in the relationships


SUPPLIES, USES, and CAN_SUPPLY, respectively

Is this equivalent to the instance (s,j,p) in ternary relationship?


Example of a ternary relationship
Supplier Project Supplier Part
Ace R1 Ace T1
Supplier Project Part Ace R2 Ace T2
Ace R1 T1 Acme R1 Acme T2
Ace R2 T2 Acme R2 Acme T1
Lowes R1 Lowes T1
Acme R1 T2
Lowes R2 Lowes T2
Acme R2 T1
Lowes R1 T1 Project Part
R1 T1
Lowes R2 T2
R1 T2
R2 T1
R2 T2
Ternary Relationships
3 binary relationships may represent different info than a single ternary relationship

TAUGHT_DURING and OFFERED_DURING are redundant, but


CAN_TEACH is not redundant
Cardinality Ratio of Ternary Relationships

A supplier can
There is 1 supplier
supply same part to
for every (project,
more than 1 project
part) combination

1 M

N
A supplier can
supply more than 1
part to a project

You might also like