0% found this document useful (0 votes)
4 views

Lecture 3

Uploaded by

alanmox441
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture 3

Uploaded by

alanmox441
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

DATABASE ESSENTIALS

Lecture 3

[email protected]
DATABASE DESIGN
• Creating a database application involves the following activities:-

✓designing of the database schema

o is the logical design of the database

✓designing of the programs that access and update the data

✓designing of a security scheme to control access to data

• The needs of the users always play a central role in the design process.
DATABASE DESIGN…
Design Phases

The database design phases are as follows:-

• Initial phase

• Conceptual design phase

• Logical design phase

• Physical design phase


DATABASE DESIGN…
Design Phases

Initial phase

• This phase characterize fully the data needs of the prospective


database users.

• The database designer interacts extensively with domain experts and


users to carry out this task.

• The outcome of this phase is a specification of user requirements.


DATABASE DESIGN…
Design Phases

Conceptual design phase


• This phase involves using a Entity-Relationship (E-R) model to translate
user requirements into a conceptual schema of the database.

• This schema provides a detailed overview of the enterprise.

• This phase results in the creation of an E-R diagram that provides a


graphic representation of the schema.
DATABASE DESIGN…
Design Phases

Conceptual design phase


• The designer has to review the schema to confirm that all data
requirements are satisfied and are not in conflict with one another.

• The designer also, has to examine the design to remove any


redundant features.

• The E-R diagram focuses on describing the data and their


relationships, rather than on specifying physical storage details.
DATABASE DESIGN…
Design Phases

Conceptual design phase


• A fully developed conceptual schema also indicates:-
✓the functional requirements
o operations (or transactions) that will be performed on the data.

o Example
▪ modifying or updating data
▪ searching for and retrieving specific data
▪ deleting data
DATABASE DESIGN…
Design Phases

Conceptual design phase


• A fully developed conceptual schema also indicates:-
✓the attributes of the entities

✓the relationships among the entities

✓constraints on the entities

✓relationships
DATABASE DESIGN…
Design Phases

Logical design phase


• This phase involves mapping the conceptual schema onto the
relational data model.

Physical design phase


• This phase involves specifying the physical features of the database.
• This include the physical storage media.
DATABASE DESIGN…
• The physical schema of a database can be changed easily after an
application has been built.

• Logical schema are harder to change after an application has been


built.

• Changes to the logical schema may affect a number of queries and


updates scattered across application code.
DATABASE DESIGN…
When designing a database schema, always avoid the following
pitfalls:

• Redundancy

✓caused by repeated information

✓leads to inconsistency

o information is updated without taking precautions to update all


copies of the information.
DATABASE DESIGN…
When designing a database schema, always avoid the following
pitfalls:

• Incompleteness

✓this happens when some data are missing

✓this might make certain aspects of the enterprise difficult or


impossible to model
DATA MODELS
• Data model refers to a collection of conceptual tools for describing
data, data relationships, data semantics, and consistency constraints.

• Data models include but not limited to:-

✓Entity-Relationship (E-R) model

✓Relational model
ENTITY-RELATIONSHIP (E-R) MODEL
• E-R model is a graphical approach to database design that shows
how entities are related to each other.

• It maps the meanings and interactions of real world enterprises onto a


conceptual schema.
ENTITY-RELATIONSHIP (E-R) MODEL
• It provides a means of identifying entities to be represented in the
database and how those entities are related.

• The E-R data model employs three basic concepts:


✓entity sets
✓relationship sets
✓attributes
ENTITY-RELATIONSHIP (E-R) MODEL
Terminologies
Enterprise
• Enterprise refers to any kind of organization.
• Example: colleges, schools, banks, company
ENTITY-RELATIONSHIP (E-R) MODEL
Terminologies
Entity
• Entity refers to an object or thing in real world.

• An entity may be concrete, such as a person or a book, or it may be


abstract, such as a course, or a flight reservation.

• Example:
✓students of colleges and schools
✓loans in banks
✓employees in a company
ENTITY-RELATIONSHIP (E-R) MODEL
Terminologies
Attributes/properties
• These are the characteristics of any entity.

• Example:
1. A student can be described by his/her student id, name, age,
address, height, class
2. Loans can be described by their types such as house loan, car loan
3. Employees in a company can be described by their Employee ID,
name, department, designation
ENTITY-RELATIONSHIP (E-R) MODEL
Terminologies
Value
• Value is the information or data which is stored in attributes of any
entity.

• Example:
attribute value
student_id 0001
name Clatous
age 30
address Mbezi
ENTITY-RELATIONSHIP (E-R) MODEL
Terminologies
Entity Sets
• All the entities having same attributes make an entity set.

• An entity set is represented in an E-R diagram by a rectangle, which is


divided into two parts
✓First part contains the name of the entity set, the second part contains
the names of all the attributes of the entity set.
ENTITY-RELATIONSHIP (E-R) MODEL
Terminologies
Domain
• Domain or value set is the set of all values or information about any attribute.
ENTITY-RELATIONSHIP (E-R) MODEL
Terminologies
ENTITY-RELATIONSHIP (E-R) MODEL
Entity sets are categorized as follows:
1. Strong entity set
• Refers to an entity set having any key attributes.

2. Weak entity set


• Refers to an entity set having no key attributes.
TYPES OF ATTRIBUTES
Attributes can be characterized by the following types:
1. Simple and Composite Attributes
• Simple attribute
• An attribute that cannot be divided into subparts.
• Example: age of a student

• Composite attribute
• An attribute that can be divided into subparts.
• Example: name of a student can be divided into first name, middle
name and last name.
TYPES OF ATTRIBUTES
Attributes can be characterized by the following types:
2. Single Valued and Multi-valued Attributes
• Single valued attribute
• An attribute having only single value for a particular entity.
• Example: age of a student.

• Multi-valued attribute
• An attribute having more than one possible value for a particular
entity is known as multi-valued attribute.
• Example: phone number of a student. A student may have more than
one phone number.
TYPES OF ATTRIBUTES
Attributes can be characterized by the following types:
3. Derived Attributes and Stored Attributes
• Derived Attribute
• An attribute that can be derived from other known attributes.
• The value of a derived attribute is not stored but is computed when
required.
• Example: Age of an employee can be derived if you know date of
birth and system date.

• Stored Attribute
• An attribute which cannot be derived by other known attributes.
• Example: Date of birth of any employee.
RELATIONSHIP
• A relationship refers to the association among several entities.

• Connects different entities through a meaningful relation.

• Example:
✓ a relationship advisor that associates instructor Samwel with student Hamida.
RELATIONSHIP…
• A relationship set is a set of relationships of same type.

Relationship set advisor


RELATIONSHIP…
• A relationship instance represents an association between the named
entities in the real-world enterprise.

• A relationship set is represented in an E-R diagram by a diamond, which is


linked via lines to a number of different entity sets (rectangles).

E-R diagram showing relationship set advisor


RELATIONSHIP…
• Descriptive attributes refers to attributes of a relationship set.

• An attribute of a relationship set is represented in an E-R diagram by an


undivided rectangle.

• This rectangle is linked to the diamond representing that relationship set with
a dashed line.
Descriptive attribute
RELATIONSHIP…
Degree of relationship sets
• Refers to the total number of entity sets participating in a relationship set.

• Types of degree of relationship sets


1. Unary Relationship Set
2. Binary Relationship Set
3. Ternary Relationship Set
RELATIONSHIP…
Unary Relationship Set
• A relationship set where only one entity set participates in a
relationship set (degree 1).
Employee Reports_to Employee

e1
r1
e2
r2 e1
e3
r3 e3
e4
r4
e5
RELATIONSHIP…
Binary Relationship Set
• A relationship set where only two entity sets participates in a
relationship set (degree 2).
RELATIONSHIP…
Ternary Relationship Set
• A relationship set in which three entity sets participates in a
relationship set (degree 3).
RELATIONSHIP…
• A role of an entity refers to a function that entity plays in a relationship.

• Example
An employee plays the role of worker in his/her department

• A recursive relationship set refers to a situation when the same entity sets
participate in same relationship set more than once with different roles
each time.

• Example
A manager (employee) supervises a subordinate (employee).
MAPPING CARDINALITIES
(CARDINALITY RATIOS)
• Mapping cardinalities refers to the number of entities to which another
entity can be associated via a relationship set.

• Types of cardinalities
• One to One (1 : 1)
• One to Many (1 : N)
• Many to One (N : 1)
• Many to Many (M : N)
MAPPING CARDINALITIES
(CARDINALITY RATIOS)
One to One (1 : 1)
• An entity in table X is associated with at most one entity in table Y and an
entity in table Y is associated with at most one entity in table X.

• Example
MAPPING CARDINALITIES
(CARDINALITY RATIOS)
One to Many (1 : N)
• An entity in table X is associated with any number of entities in table Y. An
entity in table Y is associated with at most one entity in table X.

• Example
MAPPING CARDINALITIES
(CARDINALITY RATIOS)
Many to One (N : 1)
• An entity in table X is associated with at most one entity in table Y. An entity
in table Y is associated with any number of entities in table X.

• Example
MAPPING CARDINALITIES
(CARDINALITY RATIOS)
Many to Many (M : N)
• An entity in table X is associated with any number of entities in table Y and
vice versa.

• Example
Successful and unsuccessful people
do not vary greatly in their abilities.
They vary in their desires to reach
their potential. –
John Maxwell

You might also like