You are on page 1of 31

Database

TDB2073
Structured Programming & Database
Systems
Course Objectives

• To know the differences between data and


information
• To understand what a database is
• To appreciate the importance of database
design
• To discern the components of Entity
Relationship Diagram (ERD)
• To create a ERD based on business rules
Data vs Information

• Data: raw facts


– Constitute building blocks of information
• Information: is produced by processing
data and reveals meaning of data
– Good, timely, relevant information key to
decision making
– Good decision making key to organizational
survival
The Process of Transforming Data into Information

Source : Principles of Information Systems, Seventh Edition


Relationship between Data and Database

• Useful information requires accurate DATA


• Therefore, DATA must be
– Generated properly
– Stored in a format that is easy to access and
process
– Managed carefully
Relationship between Data, Data Management and Database

• Therefore , we need …

ge m en t
ma n a
Data

• Discipline that focuses on proper


• generation,
• storage and
• Retrieval of data
Relationship between Data, Data Management and Database

• Efficient data management requires the


use of a computer database
• Database :
– shared, integrated computer structure that
stores a collection of data
– designed to meet the information needs of an
organization.
Example of Database view
Database Systems

Ever use any database


system applications before?

Name any database system


applications you know?
Examples of Database System Applications

Library system
Travel booking system

Timetabling system
What is Conceptual Database Design?

• Process of describing the data, relationships


between the data, and the constraints on the
data.
• After analysis - Gather all the essential data
required and understand how the data are
related
• The focus is on the data, rather than on the
processes.
Entity-Relationship (ER) Modeling.

• ER Modeling is an approach to database


design.
• Entity Relationship (ER) Diagram
– A detailed, logical representation of the entities,
associations and data elements for an organization or
business
• ERD represents conceptual database as viewed
by end user
• ERDs depict database’s main components:
– Entities
– Attributes
– Relationships
• 2 types of Models
– Chen Notation (will be used in this class)
– Crow’s Foot
Chen Notation
Association
between the
instances of one or
more entity types

Verb Phrase AttributeName


EntityName

Person, place, object, event


or concept about which data named property or
is to be maintained characteristic of an
entity
Crow’s Foot Model

Entity
Entity Attribute
Attribute Relationship
Relationship

EntityName
EntityName Verb phrase

List of
Attributes
Entity

• 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.
Attribute

• 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.
• Three types
– Normal attribute
– Candidate key attribute
– Referential attribute
Attribute : Identifier Attribute

• 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
– A candidate key that has been selected as the unique
identifying characteristic for an entity type
Attribute : Referential Attribute
• Make Reference to another instance in another table
Referential attribute:

Candidate key - Ties the lecturer entity to another


entity that is department.
- Foreign key

Name
Name IdNum
IdNum DeptID
DeptID Email
Email
Ali
Ali 123367
123367 MH
MH ali@a.com
ali@a.com
Batyr
Batyr 106768
106768 CIS
CIS batyr@a.com
batyr@a.com
Rama
Rama 137563
137563 ENG
ENG rama@a.com
rama@a.com
Lim
Lim 108222
108222 FOU
FOU lim@a.com
lim@a.com
Instance of
Lecturer.
Example of Entity and Attribute in Chen Notation

DeptId email

IdNum Name

LECTURER

Candidate Key
attribute
Relationship


 Associations
Associations between
between instances
instances of
of one
one oror more
more entity
entity types
types that
that is
is of
of interest
interest

 Given
Given aa name
name that
that describes
describes its
its function.
function.
•• relationship
relationship name
name is
is an
an active
active or
or aa passive
passive verb.
verb.

Relationship name:
teaches

Lecturer
Student

A lecturer teaches one or more students.


A student can be taught by one or more
lecturers.
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 Connectivity
• many – to –many

• Cardinality : minimum and maximum number of


instances of Entity B that can (or must be)
associated with each instance of entity A.
– Can be derived from constraints
– Ex : Each bank has maximum 3 account types

Bank has Account_Type


Cardinality and Connectivity

Lecturer teaches Class

A lecturer teaches class OR


A class is taught by lecturer

How
Many??
Cardinality and Connectivity

Connectivity

Professor
1 teaches
M Class
(1,1) (1,4)

Cardinality
A professor teaches many class
A class is taught by at most one professor
A professor teaches minimum 1 class and maximum 4 classes
Developing an ER Diagram

• Database design is an iterative process


Create detailed
narrative of
organization’s
description of
operations

Identify business rules


Revise and Review
based on description
ERD
of operations

Identify attributes and


Identify main entities
primary keys that
and relationships from
adequately describe
business rules
entities

Develop initial ERD


Example of Business Rules

• Business rules for a bank database:


– A bank can have many branches.
– The bank has several types of loan. Minimum number of loan
type is 1 and maximum is 3.
– Each branch has several types of account i.e saving account,
current account and join account. Each branch has exactly 3
types of account.
– Each of the branches can give loans to customers.
– Each of the branches can maintain bank accounts for the
customers.
– A customer can have minimum of 1 account and maximum of 3.
– A customer can have minimum of 0 loan and maximum of 2.
Example of ERD

Code BrCode
HAS BRANCH
BANK
Address
(1,1) (1,1)
Name
Street
City
HAS
HAS
(3,3) (1,3)
TypeNo TypeNo
ACCOUNT_TYPE LOAN_TYPE

Type HAS
Type
HAS

CUST_ACC CUST_LOAN
CustNo
CustNo
(1,3) (0,2)

TypeNo TypeNo
HAS HAS
(1,1)
(1,1)
DOB
CustAge CUSTOMER
CustNo
City CustAddr
CustName
Example of ERD Component
Summary

• Data are raw facts


• Information is the result of processing data to reveal its
meaning
• Accurate, relevant, timely information is the key to good
decision making
• Data usually stored in a database
• DBMS implements a database and manages its contents
• Database design defines the database structure
– Well-designed database facilitates data management, generates
valuable information
– Poorly-designed database leads to bad decision making,
organizational failure
Summary
• Entity relationship (ER) model
– Uses ERD to represent conceptual database as viewed
by end user
– ERM’s main components:
• Entities
• Relationships
• Attributes
– Includes connectivity and cardinality notations
• Connectivities and cardinalities are based on business rules
• M:N relationship is valid at conceptual level
– Must be mapped to a set of 1:M relationships
Reference

• Database Systems Design,


Implementation, & Management, Seven
Edition
– Peter Rob & Carlos Coronel
– ISBN 1-418-83593-5
– Thompson
• http://www.cs.nott.ac.uk/~bai/DBS/exercis
e1.html

You might also like