Вы находитесь на странице: 1из 49

Lesson3

Conceptual Modelling using


ERD
(with focus on Chen Notation)

Lesson Outcomes
At the end of the lesson, students should be able to :
Conceptually depict a database structure in an ER Diagram
(using Chen Notation)
Identify and describe the main characteristics of ERDs
components such as
Entity
Attributes
Identifier attributes (Keys) Primary/Composite/Foreign
Composite and simple attributes
Single-valued and Multivalued attributes

Relationships
Connectivity & cardinality
Degree of relationship
2

name

custID
qtyBought

price

prodID

PRODUCT

purchasedBy

name

CUSTOMER

m
contactNo
suppliedBy
suppID

1
SUPPLIER

name

address

contactNo

Intro to Modeling
In the programming env., a problem that needs to be solved
must be critically analyze first before a solution can be designed.
In programming, the analysis will identify (1) the inputs (2) the
outputs (3) the process
After that an approach to solve the problem will be selected, e.g.,
procedural/structured, object-oriented, logical etc.
Then, if for example, structured approach is selected, then the
solution will be designed using certain model, e.g., flowchart,
pseudocode, etc.
4

Intro to Modeling contd


After that only the actual coding will be done using certain
programming language, e.g., C.
The C compiler itself can be provided by many publishers
such as Turbo C, Borland C, etc.

Intro to Entity Relationship (ER) Model


The same concept applies in database development
In the database env., a problem that needs to be solved must be
critically analyze first before a solution can be designed. (Here the
problem is to keep storage of data for later use)
The analysis will identify (1) the structure of the storage (2) the
transactions/operations to be done
Then, the solution will be depicted using certain model, e.g., ER,
UML
For structure : ER Diagram, UML Class Diagram, etc.
For transaction: relational algebra, etc.
6

Entity Relationship (ER) Model contd


After that a solution will be refined using certain
approach, e.g., relational, object-oriented, network,
hierarchical, etc.
After that only the actual coding will be done using
database language called Structured Query Language
(SQL).
Again SQL is supported by many database software,
e.g., Oracle, MySQL, Informix, SQL Server, etc.

Entity Relationship (ER) Model contd


Database Structure Modeling using ERD
ERD is a pictorial representation of a database structure.
Different shapes of items in the diagram represents
different components of the database.
Entities
Attributes
Relationships
There are many variations in terms of the shapes. The
popular ones are based on Chen and Crow foot
notations.
8

Variation in ER Model
One-to-One

One-to-Many
CUSTOMER

ACCOUNT

STUDENT

COURSE

CUSTOMER

ACCOUNT

STUDENT

COURSE

ACCOUNT

STUDENT

COURSE

ACCOUNT

STUDENT

EMPLOYEE

TEMP_EMP

EMPLOYEE

TEMP_EMP

EMPLOYEE

TEMP_EMP

CUSTOMER

TEMP_EMP

CUSTOMER

3
4
5

EMPLOYEE

EMPLOYEE

TEMP_EMP

Many-to-Many

CUSTOMER

ACCOUNT

(1) Ross, (2) Bachmann, (3) Martin (crow foot), (4) Chen, (5) Rumbaugh.

STUDENT

COURSE

COURSE

Chen Notation
Association
between the
instances of one or
more entity types
EntityName

Person, place, object, event


or concept about which data
is to be maintained
Represents a set or collection of
objects in the real world that
share the same properties

Verb Phrase

AttributeName

named property or
characteristic of an
entity

Entities

Refers to entity set and not to single entity


occurrence
Corresponds to table and not to row in relational
environment
In both Chen and Crows Foot models, entity is
represented by rectangle containing entitys
name
Entity name, a noun, is usually written in capital
letters
11

Entities contd
Examples of entities:

Person: EMPLOYEE, STUDENT, PATIENT


Place: STORE, WAREHOUSE
Object: MACHINE, PRODUCT, CAR
Event: SALE,REGISTRATION, RENEWAL
Concept: ACCOUNT, COURSE

Guidelines for naming and defining entity types:

An entity type name is a singular noun


An entity type should be descriptive and specific
An entity name should be concise
Event entity types should be named for the result of the event, not
the activity or process of the event.

Attributes
Characteristics of entities
In Chen model, attributes are represented by ovals
and are connected to entity rectangle with a line
Each oval contains the name of attribute it
represents
In Crows Foot model, attributes are written in
attribute box below entity rectangle (oval also
acceptable)

13

Attributes contd
Example of entity types and associated attributes:
STUDENT: Student_ID, Student_Name, Home_Address,
Phone_Number, Major

Guidelines for naming attributes:


An attribute name is a noun.
An attribute name should be unique
To make an attribute name unique and clear, each attribute name
should follow a standard format
Similar attributes of different entity types should use similar but
distinguishing names.

Composite vs Simple Attributes


Attributes can be simple OR composite
Composite attribute (NOT composite key) can be
subdivided to yield additional attributes.
an ADDRESS attribute can be subdivided into city,
state and postcode
NAME attribute can be subdivided into first_Name
and Last_Name
Simple attribute cannot be subdivided.
Ex. AGE, MARITAL STATUS

15

Composite vs Simple Attributes

Composite
attribute
Simple
attribute

fname

age

name

STUDENT

lname

16

Single-Valued vs Multivalued Attributes


Single-value attribute can
have only a single value

Ex. CAR_MODEL_NO

Not necessarily a simple


attribute
Ex. IC_NUM => 780417-08-5284
is a composite attribute because
it can be subdivided into
birthdate (780417), place of
birth (08), serial number (5284)

Multivalued attributes
can have many values
Ex. A car color may be
subdivided into many
colors (colors for the
roof, body and trim)
Chen Model, the
multivalued attributes are
shown by double line
connecting the attribute
to the entity.
17

Multivalued Attributes (continued)

18
ERD :: 19 / 1 / 07

18

Resolving Multivalued Attribute Problems


Although conceptual model can handle multivalued
attributes, you should not implement them in relational
DBMS
Option 1: Within original entity, create several new
attributes, one for each of the original multivalued
attributes components
Can lead to major structural problems in table

Option 2: Create new entity composed of original


multivalued attributes components
19

Resolving Multivalued Attribute Problems


(continued)
Option 1: Within original entity, create several new attributes

20
ERD :: 19 / 1 / 07

20

Resolving Multivalued Attribute Problems


(continued)
Option 2: Create new entity composed of original multivalued
attributes components

21
ERD :: 19 / 1 / 07

21

Identifier vs non-identifierAttributes
Non-identifier
Attribute which is not unique among instances of an entity

Candidate key
Attribute (or combination of attributes) that uniquely identifies each
instance of an entity type
Some entities may have more than one candidate key
Ex: A candidate key for EMPLOYEE is Employee_ID, a second is the
combination of Employee_Name and Address.
If there is more than one candidate key, need to make a choice.

Identifier/primary key
A candidate key that has been selected as the unique identifying
characteristic for an entity type

Example
Chen Notation
Name

Gender

IC

StaffID

Staff

Crows Foot Notation


Staff
PK StaffID

Name
Gender
IC

Referential/foreign key Attributes

Make Reference to another instance in another table


Referential attribute: Ties the lecturer entity to
another entity that is department.

Instance of Lecturer.

Name

IdNum

DeptID

Email

Ali

105

LG

ali@a.com

Mary

106

IT

mary@a.com

John

107

ENG

john@a.com

Lim

108

IT

lim@a.com

Derived Attributes
Attribute whose value may be calculated (derived) from
other attributes.
Ex. EMP_AGE can be derived by computing the difference between
the current date and the EMP_DOB

Need not be physically stored within database.


Can be derived by using an algorithm.
Chen Model, the derived attribute is connected to the
entity using dashed line.

25

Relationships
Associations between instances of one or more entity types that is of interest
Given a name that describes its function.
relationship name is an active or a passive verb.

Relationship name:
writes
Author

Book

An author writes one or more books


A book can be written by one or more authors.

Degree of Relationships
Degree: number of entity types that participate in a relationship
Three cases
Unary: between two instances of one entity type
Binary: between the instances of two entity types
Ternary: among the instances of three entity types

Cardinality and Connectivity


Relationships can be classified as either
one to one
one to many
many to many

Connectivity

Cardinality : minimum and maximum number of


instances of Entity B that can (or must be)
associated with each instance of entity A.

Cardinality and Connectivity

Professor

Professor

teaches

teaches

Class

Class

A professor teaches class OR


A class is taught by professor

How Many??

Cardinality and Connectivity


Connectivity

1
Professor

M
teaches

(1,4)

Class

(1,1)
Cardinality

Connectivity
teaches

Professor

(1,1)

Class

(1,4)
Cardinality

Connectivity
Chen Model
1 to represent one.
M to represent many

1
M

Crows Foot
One
many
One or many
Mandatory one , means (1,1)
Optional? well see after this

Binary Relationships

1:M relationship

Relational modeling ideal

Should be the norm in any relational database design

The 1: M relationship between PAINTER and PAINTING

The Implemented 1:M relationship between PAINTER and PAINTING

Binary Relationships

1:1 relationship

Should be rare in any relational database design


A single entity instance in one entity class is related to a single entity
instance in another entity class
Could indicate that two entities actually belong in the same table

The 1:1 Relationship Between PROFESSOR and DEPARTMENT

The Implemented
1:1 Relationship
Between
PROFESSOR
and
DEPARTMENT

Binary Relationships

M:N relationships

Must be avoided because they lead to data redundancies.

Can be implemented by breaking it up to produce a set of 1:M


relationships

Can avoid problems inherent to M:N relationship by creating a


composite entity or bridge entity

This will be used to link the tables that were originally related
in a M:N relationship

The composite entity structure includes-as foreign keys-at


least the primary keys of the tables that are to be linked.

The M:N Relationship Between STUDENT and CLASS


Bowser
Smithson

Accounting 1 (ACCT-211)
Intro to Microcomputing (CIS-220)
Intro to Statistics (QM-261)

This CANNOT be implemented as shown next..

The tables have many redundancies!!

+ CLASS_CODE
CLASS_CODE

+ STU_NUM

Changing the M:N relationship to TWO 1:M relationships

The database designer has 2 main options to


define a composite tables primary key:
either
use the combination of those foreign
keys or create a new primary key.

Foreign keys reference the primary keys in the


other tables of which it has a relationship with

Converting the M:N relationship into TWO 1:M relationships

Mandatory vs. Optional Cardinalities


Specifies whether an instance must exist or can be absent in the
relationship
Mandatory

Optional

handles

Lecturer
(1,1)

Lecturer

1
(0,N)

Class
(0,N)
M

handles

Class
(1,1)

A Lecturer may handle zero or many classes.

A class is handled by one and only one Lecturer.

Weak Entities
Weak entity meets two conditions
Existence-dependent
Cannot exist without entity with which it has a
relationship

Has primary key that is partially or totally derived


from parent entity in relationship
Database designer usually determines whether an
entity can be described as weak based on business
rules
42

Weak Entities (continued)

43
ERD :: 19 / 1 / 07

43

Recursive Relationships
Relationshiptypewheresameentitytype
participatesmorethanonceindifferentroles
Relationship can exist between
occurrences of the same entity set
Naturally found within unary relationship

44

Recursive Relationships

45

Recursive Relationships (continued)

46
ERD :: 19 / 1 / 07

46

Recursive Relationships (continued)

47
ERD :: 19 / 1 / 07

47

How to Evaluate a Data Model?


A good data model has the following:
Accuracy and completeness
Non redundancy
Enforcement of business rules
Data Reusability
Stability and Flexibility
Communication Effectiveness
Simplicity

Lesson Summary
ERD is a diagram that can be used to represent structure
of a database.
There are 3 main components of a database structure (1)
entity (2) attribute (3) relationship
All entities must be directly connected to at least one
other entity in the ERD.

Вам также может понравиться