You are on page 1of 40

4

Database Design
4

Data Modeling

• Data modeling is a technique for organizing and


documenting a system’s DATA. Data modeling is
sometimes called database modeling because a
data model is usually implemented as a database.
4

Steps in developing a database

• Requirements analysis →
• Conceptual Database design →
• Logical Database design →
• Schema refinement →
• Physical Database design
• Applications and security
4
Conceptual design: (ER Model is used
at this stage.)

• What are the entities and relationships in the


enterprise?

• What information about these entities and


relationships should we store in the database?

• What are the integrity constraints or business rules


that hold?

• A database `schema’ in the ER Model can be


represented pictorially (ER diagrams).

• Can map an ER diagram into a relational schema.


4

Entity/Relationship Modelling

• E/R Modelling is used • Example


for conceptual design – In a University database
– Entities - objects or we might have entities
for Students, Modules
items of interest
and Lecturers. Students
– Attributes - facts about, might have attributes
or properties of, an such as their ID, Name,
entity and Course, and could
– Relationships - links have relationships with
Modules (enrolment) and
between entities
Lecturers (tutor/tutee)
4

Entity/Relationship Diagrams

• E/R Models are often Lecturer ID

represented as E/R Name Course


diagrams that
– Give a conceptual view
of the database Tutors Student
– Are independent of the
choice of DBMS
– Can identify some
problems in a design Module Studies

Entity Relationship Modelling


4

Entities

• Entities represent • Entities have


objects or things of – A general type or class,
interest such as Lecturer or
– Physical things like Module
students, lecturers, – Instances of that
employees, products particular type, such as
– More abstract things Kashif, Imran are
like modules, orders, instances of Lecturer
courses, projects – Attributes (such as
name, email address)

Entity Relationship Modelling


4

Diagramming Entities

• In an E/R Diagram, an Lecturer ID

entity is usually drawn Name Course


as a box with rounded
corners
Tutors Student
• The box is labelled
with the name of the
class of objects
represented by that Module Studies
entity

Entity Relationship Modelling


4

Attributes

• Attributes are facts, • Attributes have


aspects, properties, or – A name
details about an entity – An associated entity
– Students have IDs, – Domains of possible
names, courses, values
addresses, … – Values from the domain
– Modules have codes, for each instance of the
titles, credit weights, entity they are belong
levels, … to

Entity Relationship Modelling


4

Classes of attributes
• Simple attribute
• Composite attribute
• Derived attributes
• Single-valued attribute
• Multi-valued attribute

10
4

Simple/Composite attribute
• A simple attribute cannot be subdivided.
– Examples: Age, Gender, and Marital status
• A composite attribute can be further
subdivided to yield additional attributes.
– Examples:
• ADDRESS -- Street, City, State, Zip
• PHONE NUMBER -- Area code, Exchange number

11
4

Derived attribute
• is not physically stored within the database
• instead, it is derived by using an algorithm.
– Example 1: Late Charge of 2%
• MS Access: InvoiceAmt * 0.02
– Example 2: AGE can be derived from the date of
birth and the current date.
• MS Access: int(Date() – Emp_Dob)/365)

12
4

Single-valued attribute
• can have only a single (atomic) value.
– Examples:
• A person can have only one social security number.
• A manufactured part can have only one serial
number.
– A single-valued attribute is not necessarily a
simple attribute.
• Part No: CA-08-02-189935
• Location: CA, Factory#:08, shift#: 02, part#: 189935

13
4

Multi-valued attributes
• can have many values.
– Examples:
• A person may have several college degrees.
• A household may have several phones with different
numbers
• A car color

14
4

Diagramming Attributes

• In an E/R Diagram Lecturer ID

attributes may be Name Course


drawn as ovals
• Each attribute is
Tutors Student
linked to its entity by a
line
• The name of the
attribute is written in Module Studies
the oval

Entity Relationship Modelling


4

Relationships

• Relationships are an • Relationships have


association between – A name
two or more entities – A set of entities that
– Each Student takes participate in them
several Modules – A degree - the number
– Each Module is taught of entities that
by a Lecturer participate (most have
– Each Employee works degree 2)
for a single Department – A cardinality ratio

Entity Relationship Modelling


4

Cardinality Ratios

• Each entity in a • One to one (1:1)


relationship can – Each lecturer has a
unique office
participate in zero,
• One to many (1:M)
one, or more than one – A lecturer may tutor many
instances of that students, but each
relationship student has just one tutor
• Many to many (M:M)
• This leads to 3 types
– Each student takes
of relationship… several modules, and
each module is taken by
several students

Entity Relationship Modelling


4

Diagramming Relationships

• Relationships are Lecturer ID

links between two Name Course


entities
• The name is given in a
Tutors Student
diamond box
• The ends of the link
show cardinality
Module Studies

One Many

Entity Relationship Modelling


4

Removing M:M Relationships

• Many to many Student


relationships are
difficult to represent Student
Has
• We can split a many to
many relationship into
Studies Enrolment
two one to many
relationships
• An entity represents Module
In

the M:M relationship


Module

Entity Relationship Modelling


4

Making E/R Models

• To make an E/R model • General guidelines


you need to identify – Since entities are
– Enitities things or objects they
– Attributes are often nouns in the
description
– Relationships
– Attributes are facts or
– Cardinality ratios properties, and so are
• from a description often nouns also
– Verbs often describe
relationships between
entities

Entity Relationship Modelling


4

Example

A university consists of a number of


departments. Each department offers several
courses. A number of modules make up each
course. Students enrol in a particular course and
take modules towards the completion of that
course. Each module is taught by a lecturer from
the appropriate department, and each lecturer
tutors a group of students

Entity Relationship Modelling


4

Example - Entities

A university consists of a number of


departments. Each department offers several
courses. A number of modules make up each
course. Students enrol in a particular course and
take modules towards the completion of that
course. Each module is taught by a lecturer from
the appropriate department, and each lecturer
tutors a group of students

Entity Relationship Modelling


4

Example - Relationships

• A university consists of a number of


departments. Each department offers several
courses. A number of modules make up each
course. Students enrol in a particular course and
take modules towards the completion of that
course. Each module is taught by a lecturer from
the appropriate department, and each lecturer
tutors a group of students

Entity Relationship Modelling


4

Example - E/R Diagram


Entities: Department, Course, Module, Lecturer, Student

Department

Course Module Lecturer

Student

Entity Relationship Modelling


4

Example - E/R Diagram


Each department offers several courses

Offers Department

Course Module Lecturer

Student

Entity Relationship Modelling


4

Example - E/R Diagram


A number of modules make up each courses

Offers Department

Course Includes Module Lecturer

Student

Entity Relationship Modelling


4

Example - E/R Diagram


Students enrol in a particular course

Offers Department

Course Includes Module Lecturer

Enrols In Student

Entity Relationship Modelling


4

Example - E/R Diagram


Students … take modules

Offers Department

Course Includes Module Lecturer

Takes

Enrols In Student

Entity Relationship Modelling


4

Example - E/R Diagram


Each module is taught by a lecturer

Offers Department

Course Includes Module Teaches Lecturer

Takes

Enrols In Student

Entity Relationship Modelling


4

Example - E/R Diagram


a lecturer from the appropriate department

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student

Entity Relationship Modelling


4

Example - E/R Diagram


each lecturer tutors a group of students

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors

Entity Relationship Modelling


4

Example - E/R Diagram

Offers Department Employs

Course Includes Module Teaches Lecturer

Takes

Enrols In Student Tutors

Entity Relationship Modelling


4

Entities and Attributes

• Sometimes it is hard • General guidelines


to tell if something – Entities can have
should be an entity or attributes but attributes
an attribute have no smaller parts
– They both represent – Entities can have
objects or facts about relationships between
the world them, but an attribute
belongs to a single
– They are both often entity
represented by nouns
in descriptions

Entity Relationship Modelling


4

Example

We want to represent information about products


in a database. Each product has a description, a
price and a supplier. Suppliers have addresses,
phone numbers, and names. Each address is
made up of a street address, a city, and a
postcode.

Entity Relationship Modelling


4

Example - Entities/Attributes

• Entities or attributes: • Products, suppliers,


• product and addresses all
• description
have smaller parts so
• price
• supplier we can make them
• address entities
• phone number • The others have no
• name
• street address
smaller parts and
• city belong to a single
• postcode entity

Entity Relationship Modelling


4

Example - E/R Diagram


Price

Description Product

Street address

Name Supplier Address City

Phone number Postcode

Entity Relationship Modelling


4

Example - Relationships

• Each product has a • Each supplier has an


supplier address
– Each product has a – A supplier has a single
single supplier but address
there is nothing to stop – It does not seem
a supplier supplying sensible for two
many products different suppliers to
– A many to one have the same address
relationship – A one to one
relationship

Entity Relationship Modelling


4

Example - E/R Diagram


Price

Description Product

Has A Street address

Name Supplier Has A Address City

Phone number Postcode

Entity Relationship Modelling


4

Example - E/R Diagram


Price

Description Product

Has A

Name Supplier City

Phone number Postcode Street address

Entity Relationship Modelling


4

Example
“A database will be made to store information about patients in a
hospital. On arrival, each patient’s personal details (name,
address, and telephone number) are recorded where possible, and
they are given an admission number. They are then assigned to a
particular ward (Accident and Emergency, Cardiology, Oncology,
etc.). In each ward there are a number of doctors and nurses. A
patient will be treated by one doctor and several nurses over the
course of their stay, and each doctor and nurse may be involved
with several patients at any given time.”

Entity Relationship Modelling

You might also like