Sei sulla pagina 1di 30

Data Base 1

Data Modeling Using the ERD

E-R Model Introduction

There are different methods of data modeling, but


the most widely used is the Entity-Relationship (ER)
model.
ER-Model can simply be stated as data model of
the real world as entities and relationships. A basic
component of the model is the Entity-Relationship
diagram which is used to visually represent data
objects.

To make ERD we need to make the


following:

Step1: What are entities? (Tables)


Step 2:What attributes includes in each table
Step 3:What the primary key attribute in each table
Step 4: What are relations between tables
Step 5: Show the degree of participation for each
table in relation

Summary of notation for ER diagrams

Representation in ER-Model

Entities
Relationships
Attributes
Connectivity and Cardinality
ER Notation

Entities

Entities are the prime data objects about


which information is to be collected. Entities
are usually recognizable concepts, either
concrete or abstract, such as person,
places, things, or events which have
relevance to the database.

Examples - Employees and Customers

Relationships

A Relationship represents an
association between two or more
entities.
Example - Employees are assigned
projects.

Attributes

Attributes describe the entity or


relationship of which they are
associated.
Example - Troy Griffin (employees
name)

Connectivity and Cardinality

The connectivity of a relationship describes


the mapping of associated entity instances
in the relationship. The cardinality of a
relationship is the actual number of related
occurrences for each of the two entities.
There are three basic types of connectivity:

1. A one-to-one relationship.
2. A one-to-many relationship.
3. A many-to-many relationship.

Connectivity and Cardinality

A one-to-one relationship which is


when at most one instance of an entity
A is associated with one instance of
entity B.

Connectivity and Cardinality

A one-to-many relationship which


is when for one instance of entity
A, there are zero, one, or many
instances of entity B, but for one
instance of entity B, there is only
one instance of entity A.

Connectivity and Cardinality

A many-to-many relationship
which is when for one instance of
entity A, there are zero, one, or
many instances of entity B and for
one instance of entity B there are
zero, one, or many instances of
entity A.

ER Notation

There is no standard for representing data objects


in ER diagrams. Each modeling style uses its own
notation. All notational styles represent entities as
rectangular boxes and relationships as lines
connecting boxes. The standard given below is
widely used:

Attributes - Ellipses
Relationship Sets - Diamonds
Cardinalities An arrow or a 1 pointing where one
entity can be mapped

E-R Constraints

What are constraints?

A constraint is assertion about a


database that must be true at all times.

It is part of database schema.

Constraints play an important role in


determining the best database design
for an enterprise.

Why are constraints important?

It gives more semantics to the data

Allow to refer to entities eg using keys

Enables efficient storage, lookup etc.

Types of constraints

Participation constraint - If all entities in an entity


set must participate in a relation in the relationship
set, a thick line is drawn.
Two types

Total all entities of the entity set should participate in a


relation in the relationship set. With total participation Eg.
every loan has to be associated with a customer
Partial not all entities of the relation has to participate in
a relation in the relationship set. Eg. Not every customer
should be associated with a loan.
Customer

Borrow
s

Loan

Read this example

In DB for student registration we would like to keep


data about students, courses, sections within
courses and students' grades.
A course may include several sections.
Each one may be taught by different teacher.
A student may register in a course and be assigned
to a particular section within this course

18

Data kept about each student include :name, address, telephone numbers,
ID#, gender, and birth date.
For a course we would like to keep data concerning course-Id, course title,
max. grade and number of lectures given/week.
Section's data include Section#, room number where lectures are given,
teacher's name.
Section numbers are always 1, 2, ..etc. for each course.
The DB should keep the date when the student registered in the course,
his final grade

Model this problem using the ER approach

19

Step 1:
The first step to extract the entities or
tables form the last case as the
following
Course

Student

Section

Teacher

20

Step 2
To extract the attributes inside in each
Tables
Note the types of attributes as discussed before (Simple, composite,
Multivalve, derived,Key)

21

Step 3

Determine a primary key attribute for each


table
The primary attribute is the one who are
unique attribute and not allowed to be null
value

22

Step 4

Read the case again and try to extract


the relations between tables

23

Step 5

Take each relation in ERD and specify


the type of participation for each table
If it is total participation or partial
participation

24

Special cases

25

A Ternary Relationship
SID

Quantity

supplier
supply

JID

project

part

PID

26

Recursive Relationship type:


Conversion (1:M)
FN

LN
1:1
EMPLOYEE
0:N

SUPERVISES

SS
27

Binary versus non-binary


relationship
customer

vehicle

own
s

fixes
mechanic

parts

ER Advantages

Exceptional conceptual simplicity


Visual representation
Effective communication tool
Integrated with the relational data
model

ER Disadvantages

Limited constraint representation


Limited relationship representation
No data manipulation language
Loss of information content

Potrebbero piacerti anche