Chapter - 1
Chapter - 1
Institute of Technology
Department of Computer Science
Instructor Tadele D
1
Ambo University
Chapter 1
Fundamentals of Database System
(CoSc2071)
Instructor Tadele D
2
Ambo University
Fundamentals of Database System
Introduction to DB system
1.1What is Database?
Database
a collection of logically related data or records w/c is
designed to manage large data set/ records of an organization.
used to organize the data in the form of table, schema, views,
and reports, etc.
using it to easily retrieve, insert, and delete the information
Ex. College DB- used to organizes the data about the admin,
staff, students and faculty etc
Instructor Tadele D
3
Ambo University
Fundamentals of Database System
What is data?
Data
name
Instructor Tadele D
4
Ambo University
Fundamentals of Database System
1.2. Basics of Database
Database
Is represent some aspect of the real world w/c is called
mini world.
Is logically coherent collection of data with some
inherent meaning.
is defined & populated with data for a specific purpose
receives instruction from a DBA & based on such instruction load, retrieve
or modify existing data from the system.
DBMS
Instructor Tadele D
6
Ambo University
Fundamentals of Database System
DBMS
provides an interface to perform various operations like
database creation / creating a table in the database , storing data
in it, updating data in it, and a lot more.
provides protection and security to the database.
it also maintains data consistency.
That means, it allows:
Data definitions
Data updation
Data retrieval
User administration
Instructor Tadele D
7
Ambo University
Fundamentals of Database System
manages the interaction between the end user and the database
Instructor Tadele D
8
Ambo University
Fundamentals of Database System
• Data Definition:
– Standard commands through w/c data structures are
defined.
– i.e. the commands that used for creation, modification, and
removal of definition that defines the data in the database
of the organization.
– It assist storing the metadata details in the db.
• Data Up-dation:
– is used for the insertion, modification, and deletion of the
actual data in theInstructor
database.
Tadele D
9
Ambo University
Fundamentals of Database System
• Data Retrieval:
– is used to identify & extract data from a database, based on
a query provided by the user or application.
– enables the fetching of data from a database to use by
applications for various purposes.
• User Administration:
– is used for registering and monitoring users, maintain data
integrity, enforcing data security, dealing with concurrency
control, monitoring performance and recovering
information corrupted by unexpected failure
Instructor Tadele D
10
Ambo University
Fundamentals of Database System
a general purpose DBMS SW is facilitate:
the processes of defining
the processes of constructing database among various users
Defining a db
Instructor Tadele D
12
Ambo University
Fundamentals of Database System
Manipulating DB
Includes function such as:
updating the db to reflect changes in the main-world,
Generating reports for fixed query processing which
is defined during application development.
Instructor Tadele D
13
Ambo University
Fundamentals of Database System
Characteristics of DBMS
Instructor Tadele D
15
Ambo University
Fundamentals of Database System
Advantage and Disadvantage of DBMS
Advantage of DBMS
• control data redundancy b/c it stores all the data in one single
database file
– Data sharing
– Easily Maintenance
– Backup
Instructor Tadele D
17
Ambo University
Fundamentals of Database System
Disadvantage of DBMS
– Cost of Hardware and Software
• It requires a high speed of data processor and large memory size to run
DBMS software.
– Size
• It occupies a large space of disks and large memory to run them
efficiently.
– Complexity
• It create additional complexity & requirement
– Higher impact of failure
• Its failure is highly impact the db system b/c since all the data stored in
a single db, its failure cause loss of data forever.
Instructor Tadele D
18
Ambo University
Fundamentals of Database System
Database development life cycle
There are several steps in designing a db system. The major steps are:-
Planning
Data requirement & analysis
Define problems and constraints
Data base design phase
DBMS selection
proto typing
Implementation
Testing
Operational maintenances
Instructor Tadele D
19
Ambo University
Fundamentals of Database System
Instructor Tadele D
20
Ambo University
Fundamentals of Database System
Data requirement and analysis phase
Instructor Tadele D
21
Ambo University
Fundamentals of Database System
Instructor Tadele D
24
Ambo University
Fundamentals of Database System
a. conceptual design
Concise description of entities & relationship b/n
entities
No implementation / physical detail consideration
b. logical design
Instructor Tadele D
25
Ambo University
Fundamentals of Database System
attribute s
primer key
foreign key
Instructor Tadele D
26
Ambo University
Fundamentals of Database System
c. physical design
involves the actual design of a db according to
the requirement that established during
modelling
names table
names column
names column data types
Instructor Tadele D
27
Ambo University
Fundamentals of Database System
DBMS selection
At this point, it emphasis on:
selection of appropriate DBMS to support db
application
design user interface & application program
using selected DBMS
Instructor Tadele D
28
Ambo University
Fundamentals of Database System
proto typing
building a working model of a db application:
to identity features of a system that work well ,or
inadequate
to suggest improvements / even add new features
clarify user requirements
evaluate feasibility of a particular system design
Ex. Of prototype dev’t stapes :
Instructor Tadele D
29
Ambo University
Fundamentals of Database System
Instructor Tadele D
30
Ambo University
Fundamentals of Database System
Implementation
physical realization of db & application designed
Testing
exciting application program with the intent of finding
error
Operational maintenances
monitoring performance of the system & maintaining the
system
if performance falls, it requires reorganization of the db &
incorporates new requirements in to the db application.
Instructor Tadele D
32
Ambo University
Fundamentals of Database System
General patterns of db development life cycle are:
Instructor Tadele D
33
Ambo University
Fundamentals of Database System
1.3. File organization
File
is a collection of records.
record – can be accessed using primary key.
frequency of access the records can be determined by the type of
file organization.
File organization
is a logical relationship among various records.
an approach that used to describe the way in which the records are
stored.
Some of the file organization approaches are:
Manual based approach
file based approach
Database approach
Instructor Tadele D
34
Ambo University
Fundamentals of Database System
1.3. File organization Vs Data base approach
Before the advent of computerized file
handling system their is manual file handling
system w/c depends the use of:
file cabinet
drawer
Pen & pepper etc.
Instructor Tadele D
35
Ambo University
Fundamentals of Database System
Manual file handing system and its limitation
Data storage & retrieval follows the primitive & traditional way of
information handling.
I.e. data storage & retrieval will be performed by using human labour.
Inserting & retrievable is done by searching right cabinet then file and
finally information.
Instructor Tadele D
36
Ambo University
Fundamentals of Database System
Not sharable
Instructor Tadele D
39
Ambo University
Fundamentals of Database System
File-Based Approach
16
16
Instructor Tadele D
40
Ambo University
Fundamentals of Database System
1. Modification anomalies
a problem w/c experienced when one / more data valve is
modified on one application program but not on other w/c
containing the same data set.
2. Deleting anomalies
A problem that to be encountered when one record set is
deleted from one application but remain untouched in other
application program w/c contains the same record set.
Instructor Tadele D
42
Ambo University
Fundamentals of Database System
3. insertion anomalies
a problem w/c experienced when new data item to
by recorded, & the recording isn’t mode in all
application.
Data base approach
Data base
is a shared collection of logically related data w/c
designed to meet information needs of an
organization.
Instructor Tadele D
43
Ambo University
Fundamentals of Database System
Characteristic of db approach
is a centralized system
each db application will be perform the combination of:
creating db
reading db
updating db
deleting db
store information centrally
allow user to retrieve & update information
Instructor Tadele D
45
Ambo University
Fundamentals of Database System
Two / more users access & use the same data instead of storing
data in redundant manner.
in the db
DBMS
security mechanism.
h. improve decision
making.
Instructor Tadele D
49
Ambo University
Fundamentals of Database System
Instructor Tadele D
50
Ambo University
Fundamentals of Database System
Limitations and risks of db approach
Introduction of new professional and specialized
personnel
complexity in designing and managing data
high cost to be incurred to development and
maintain system
complex backup and recovery services from user
perspective
Reduce performances due to centralization and
data independence.
High impact on the system when failure occurs to
the central system.
Instructor Tadele D
51
Ambo University
Fundamentals of Database System
DBMS vs File system
In DBMS In File System
•the user is not required to write the •the user write the procedures for
procedures. managing the database.
•gives an abstract view of data that •provides the detail of the data
hides the details representation and storage of data.
Instructor Tadele D
52
Ambo University
Fundamentals of Database System
1.4 Users and actor of database system
• User of all db system may divided in to:
those who actually use & control, the content w/c
is called actors on the scene
those who enable the db to development & the
DBMS sw to be designed implemented called
workers behind the scene
Instructor Tadele D
53
Ambo University
Fundamentals of Database System
Some of the user & actors of db system are:
DBA
responsible to oversee, control & manage db resource
Instructor Tadele D
55
Ambo University
Fundamentals of Database System
Application developer
Sw programmer who design & implement the
application programs w/c to be used an interface
for db system & for maintaining the db
the one who code, test , document &maintaining
the application program
also determine interface to retrieve, insert,
update& delete data in db
Instructor Tadele D
56
Ambo University
Fundamentals of Database System
End –user
Worker who access db frequently for various purpose
use data for queries , reports & some of them actually
to update db content
Are deferent groups such as:
Casual user
users who access db occasionally
users how use sophisticated db queries to satisfy
their needs
Instructor Tadele D
57
Ambo University
Fundamentals of Database System
Naive / parametric user
make up a large section of the end-user population
unaware of DBMS
only access db based on their access level & demand
- Reservation clears
Instructor Tadele D
58
Ambo University
Fundamentals of Database System
sophistication user
users who familiar witch structure of db
&facilities of the DBMS
familiar with system capabilities
have complex requirements
have higher level of quires
E.X -business analysts, Engineers, scientist etc.
Instructor Tadele D
59
Ambo University
Fundamentals of Database System
Instructor Tadele D
60
Ambo University
Fundamentals of Database System
stand alone user
mostly maintain personal dbs using ready to use package
application
ex. a tax program user that creates his / her own internal db
Instructor Tadele D
61
Ambo University
Fundamentals of Database System
Worker behind the scene
DBMS designer & implementers
tool developer
Expects who dev ’p sw package that facilitate db
system designing & use
e.x
• code generator
• independent se vendors
Instructor Tadele D
62
Ambo University
Fundamentals of Database System
operators &maintenance personnel
System administrators who responsible for
actually running & maintaining hw & sw of db
system
Instructor Tadele D
63
Ambo University
Fundamentals of Database System
The End!
Thank you!!
Instructor Tadele D
Ambo 64
Chapter 2
Instructor Tadele D
65
Ambo University
Fundamentals of Database System
2. DBMS Architecture
DBMS design - depends upon its architecture.
The basic client/server architecture:
is used to deal with a large number of PCs, web servers, database servers
and other components that are connected with networks.
i.e. it consists of many PCs and a workstation which are connected via
the network.
DBMS architecture
- depends upon how users are connected to the database to get their request
done.
- used in design, development, implementation, and maintenance of a
database.
Instructor Tadele D
66
Ambo University
Fundamentals of Database System
Types of DBMS architecture
Database architecture
can be exists as uni-tire or multi tire.(tire/layer-is physical unit, where the code/ process runs)
Its disadvantages
is only one user can access the system at a given time via the local
client.
The presentation layer runs on a client and the data stored on the server.
In 2-tire architecture
applications on the client end can directly communicate with the database at the
server side.
it uses API's like: ODBC (Open Database Connectivity) which allows the client-
side program to call the DBMS.
user interfaces and application programs are run on the client-side.
In 3-tire architecture
client can't directly communicate with the server.
database also has no idea about any other user beyond the application.
Fig.3-Tier architecture
Instructor Tadele D
72
Ambo University
Fundamentals of Database System
how database structure will be used to store and manage end-user data.
Database schema
i.e. is the formal description of the structure of database w/c supported by DBMS
represents the logical view of the entire database by using the visual diagram.
i.e. contains schema objects like table, foreign key, primary key, views, columns,
Instructor Tadele D
73
Ambo University
Fundamentals of Database System
Instance
is the set of information / data currently stored in a database at a specific time.
Model
Data Modeling
more easily understood abstractions that define entities and the relations among
them.
Instructor Tadele D
74
Ambo University
Data Modeling (cont….)
end users.
Data Model
define how data is connected to each other and how they are processed and
graphical.
Instructor Tadele D
75
Ambo University
Data Modeling (cont….)
Data model
a blueprint that containing all the instructions to build a database that will
nature.
transformations.
Instructor Tadele D
76
Ambo University
Data Modeling (cont….)
Instructor Tadele D
77
Ambo University
Data Modeling (cont….)
An entity
An attribute
A characteristic of an entity.
Instructor Tadele D
78
Ambo University
Data Modeling (cont….)
A relationship
Describes an association among entities.
A constraint
A restriction which placed on the data.
Instructor Tadele D
79
Ambo University
Data Modeling (cont….)
Hierarchical model
Was developed in the 1960s to manage large amounts of data for complex
manufacturing projects.
Instructor Tadele D
80
Ambo University
Data Modeling (cont….)
of the segment
Each parent can have many children, but each child has only
Network model
M relationships.
But unlike the hierarchical model, the network model allows a record
In network model
Ex.
Schema, which is the conceptual organization of the entire database as viewed by the
database administrator.
Subschema, which defines the portion of the database “seen” by the application
programs that actually produce the desired information from the data contained within
the database.
Data manipulation language (DML), which defines the environment in which data
Data definition language (DDL), which enables the database administrator to define
Relational Model
Instructor Tadele D
84
Ambo University
Data Modeling (cont….)
Its ability to hide the complexities of the relational model from the user.
are stored.
RDBMS
Uses SQL to translate user queries into instructions for retrieving the
requested data.
Instructor Tadele D
86
Ambo University
Data Modeling (cont….)
Tables are related to each other through the sharing of a common attribute
Ex. CUSTOMER table contain a sales agent’s number /code that is also
contained in the AGENT table .
Instructor Tadele D
87
Ambo University
Data Modeling (cont….)
ER model
database structure.
based on:
Entity
Instructor Tadele D
89
Ambo University
Data Modeling (cont….)
Relationship
entities.
Instructor Tadele D
90
Ambo University
Data Modeling (cont….)
ER model
relationship types.
manages
STUDENT COURSE
Enrolls
(OODBMS).
Instructor Tadele D
92
Ambo University
Data Modeling (cont….)
An object
An abstraction of a real-world entity.
Date of Birth.
the balance.
interest method.
Instructor Tadele D
94
Ambo University
Data Modeling (cont….)
PERSON class.
EMPLOYEE will inherit all attributes and methods from PERSON class.
Instructor Tadele D
95
Ambo University
Database System Concepts and Architecture
2.3 Architecture and Data Independence
In early 1970s, the American National Standards Institute (ANSI) Standard
Instructor Tadele D
96
Ambo University
Database System Concepts and Architecture (cont….)
Major purpose of a database system architecture
Once a specific DBMS has been selected, the internal model maps the
Internal model
constructs. I.e. entities in the conceptual model are mapped to tables in the
relational model.
Instructor Tadele D
98
Ambo University
Database System Concepts and Architecture (cont….)
For example, if a relational database has been selected, the internal schema
change in the DBMS software requires that the internal model be changed to
model.
Instructor Tadele D
99
Ambo University
Database System Concepts and Architecture (cont….)
(b) Conceptual Model
entire organization.
is the basis for the identification and high-level description of the main data
objects
Describes the structure of the whole database including what data are stored
model.
the model.
Instructor Tadele D
102
Ambo University
Database System Concepts and Architecture (cont….)
In conceptual level
ER model
Instructor Tadele D
103
Ambo University
Database System Concepts and Architecture (cont….)
Instructor Tadele D
104
Ambo University
Database System Concepts and Architecture (cont….)
(c) External Model
The end users’ view of the data environment. End users refer to
people who use the application programs to manipulate the data
and generate information.
High level of abstraction.
Instructor Tadele D
107
Ambo University
The end .
Thank you!!!
Instructor Tadele D
108
Ambo University
Chapter three
109
Entity-Relationship (ER) Model(cont....)
E-R Model
Entity-Relationship model
Entities
Entity UniversityStudent
Primary key
PK StudentID
Attribute StudentName
StudentDOB
StudentAge
111
Entity-Relationship (ER) Model(cont....)
Attributes
•Represents the property used to describe an entity or a relationship
•Represented by Oval and connected to the entity with a line. ID.No
112
Entity-Relationship (ER) Model(cont....)
•Examples:
A person can have only one social security number.
A manufactured part can have only one serial number.
•Examples:
A person may have several college degrees.
113
Entity-Relationship (ER) Model(cont....)
date.
Relationships
• Represents the association that exist between several entities
Enroll
or participants.
114
Entity-Relationship (ER) Model(cont....)
associated.
Connectivity
many).
115
Entity-Relationship (ER) Model(cont....)
Constraints
116
Entity-Relationship (ER) Model(cont....)
117
Entity-Relationship (ER) Model(cont....)
122
Entity-Relationship (ER) Model(cont....)
124
Entity-Relationship (ER) Model(cont....)
126
Entity-Relationship (ER) Model(cont....)
127
Entity-Relationship (ER) Model(cont....)
Example 2
Build an ER Diagram for the following information:
Patients
•Name, Address, Phone #, Age
Drugs
•Name, Manufacturer , Expiration Date
128
Entity-Relationship (ER) Model(cont....)
Addr Name
Name Age
Manuf
Patients Drug
Phone
Exp
Prescrib
ed
Dosage #days
129
Entity-Relationship (ER) Model(cont....)
1. One-to-one relationship:
one entity can be related to only one other entity, and vice versa..
– For a one-to-one relationship between two entity sets E and F, key(E) and
key(F) are both keys for the relationship set.
130
Entity-Relationship (ER) Model(cont....)
131
Entity-Relationship (ER) Model(cont....)
132
Entity-Relationship (ER) Model(cont....)
133
Entity-Relationship (ER) Model(cont....)
2. One-To-Many Relationships
is easily implemented in the relational model by putting
the primary key of the 1 side in the table of the many side
as a foreign key.
In the one-to-many relationship:-
a loan is associated with at most one customer via borrower.
a customer is associated with several (including 0) loans via
borrower
134
Entity-Relationship (ER) Model(cont....)
135
Entity-Relationship (ER) Model(cont....)
136
Entity-Relationship (ER) Model(cont....)
3. Many-To-Many Relationship
is not supported directly in the relational environment.
However, M:N relationships can be implemented by creating
a new entity in 1:M relationships with the original entities.
•A customer is associated with several (possibly 0) loans via
borrower.
•A loan is associated with several (possibly 0) customers via
borrower.
137
Entity-Relationship (ER) Model(cont....)
138
Entity-Relationship (ER) Model(cont....)
139
Entity-Relationship (ER) Model(cont....)
141
Entity-Relationship (ER) Modeling
modeling
Is the first step in the database design.
it serving as a bridge between real-world
objects and the database model.
Conceptual models are used in the conceptual
design of databases, while relational models are
used in the logical design of databases.
Entity-Relationship (ER) Modeling (cont……)
Entity-Relationship model (ERM)
Is a popular high-level conceptual data model.
Form the basis of an ERD which represents the conceptual
database as viewed by the end user.
modeling tools that used to develop ERDs which form the
basis for successful database design and implementation.
ERDs
– depict the database’s main components, such as: entities,
attributes, and relationships.
Entity-Relationship (ER) Modeling (cont……)
• various notations such as Chen notation and the newer
Crow’s Foot and UML notations used with ERDs
• Chen notation and the newer Crow’s Foot notations are
used to introduce some basic Entity-Relationship (ER)
Modeling concepts
• But Some conceptual database modeling concepts are
expressed by using only the Chen notation
• However Unified Modeling Language (UML) notations
Are popular in both database and software design.
Entity-Relationship (ER) Modeling (cont……)
Beyond database design it specifies detailed design
of software modules and their interactions using
various types of diagrams.
Important part of UML is class diagrams w/c are
similar in many ways to the ER diagrams.
In class diagrams, operations on objects are specified,
in addition to specifying the database schema
structure. Operations can be used to specify the
functional requirements during database design.
Entity-Relationship (ER) Modeling (cont……)
• Generally
– Chen notation favors conceptual modeling.
• Required Attributes
Conceptual schema
Is a concise description of user’s data requirements.
Approach that enables database designers to concentrate on
After conceptual schema design, the basic data model
operations:
used to specify the high-level user queries and operations w/c
The next step in the database design is logical design or
in w/c the actual implementation of the database, using
so at this step the conceptual schema is transformed
data model.
Entity-Relationship Modeling(ERM) (cont……)
Address
Name
Employee
Entity-Relationship Modeling(ERM) (cont……)
Derived attribute
Complex Attributes.
An attribute that resulted when composite and multi-valued
attributes arbitrarily nested. For example, if a person can
have more than one residence and each residence can have
a single address and multiple phones.
Entity-Relationship Modeling(ERM) (cont……)
Entity Types, Entity Sets, Keys, and Value Sets
Entity Types
e1 c1
Girma ,55, 4000.00 Birr Microsoft,Addis Ababa,Alsan
e2
Mhamad ,55, 4500.00 Birr
e3 c2
Awash Bank, Hawsa, Tesfaye
Hunde, 45,6000.00 Birr\
.
. .
. .
. .
. .
Entity-Relationship Modeling(ERM) (cont……)
Keys
Attributes/constraint on the entities of an entity type is the
key or uniqueness constraint.
• Constraints whose values are distinct for each
individual entity in the entity set. Or its values can be
used to identify each entity uniquely.
For example, the Name attribute is a key of the COMPANY
entity type because no two companies are allowed to have
the same name.
Simple and composite key attributes
Entity-Relationship Modeling(ERM) (cont……)
Value Sets
Specifies set of values that may be assigned to that attribute for each
individual entity by using the basic data type such as integer, Boolean,
floating, enumeration, etc.
Each simple attribute of an entity type is associated with a value set
(or domain of values), which specifies the set of values that assigned
to the attribute for each individual entity.
For example1, the value set of the Age attribute of EMPLOYEE to be
specify by the set of integer numbers between 16and 70.
Example 2, the value set for the Name attribute to be specify by the
set of strings of alphabetic characters
Entity-Relationship Modeling(ERM) (cont……)
Role
Participation of an entity type in a relationship type
Each entity type - that participates in a relationship type plays a particular role in the relationship.
Role name signifies such role that a participating entity from the entity type plays in each
relationship.
For example, in the WORKS_FOR relationship types:
• EMPLOYEE plays the role of employee or worker and DEPARTMENT plays the role of department or
employer.
Role name becomes essential for distinguishing the meaning of the role that each participating
entity plays when the same entity type participates in more than one relationship type in different
roles.
Entity-Relationship Modeling(ERM) (cont……)
Structural constraints
Cardinality ratio
Participation constraint
182
Relational Data Model and the Relational Algebra
Relational model
introduced by E. F. Codd in 1970 based on predicate logic and set
theory.
Predicate logic
used extensively in mathematics, provides a framework in which
an assertion (statement of fact) can be verified as either true or
false.
For example, suppose that a student with a student ID S/234/06 is
named Hunde Dhuguma. This assertion can easily be demonstrated
to be true or false. 183
Relational Data Model and the Relational Algebra
Set theory
is a mathematical science that deals with sets, or groups of things, and
is used as the basis for data manipulation in the relational model.
For example, assume that:
set A contains three numbers: 16, 24, and 77 & represented as A (16,
24, and 77).
Set B contains four numbers: 44, 77, 90, and 11, and represented as B
(44, 77, 90, and 11).
Based on this, the intersection of A and B result set with a single
number, 77 which expressed as A _ B = 77. In other words, A and B
share a common value, 77.
184
Relational Data Model and the Relational Algebra (cont...)
defined components:
185
Relational Data Model and the Relational Algebra (cont...)
187
Relational Data Model and the Relational Algebra (cont...)
Table
189
Relational Data Model and the Relational Algebra (cont...)
Ex.
Table name: STUDENT
190
Relational Data Model and the Relational Algebra (cont...)
191
Relational Data Model and the Relational Algebra (cont...)
Logical. Logical data can only have true or false (yes or no) values. In
student table above, the STU_TRANSFER attribute uses a logical data format.
The column’s range of permissible values is known as its domain. Because
the STU_GPA values are limited to the range 0–4, inclusive, the domain is [0,
4].
The order of rows and columns is immaterial to the user.
Each table must have a primary key. In general terms, the primary key (PK)
is an attribute (or a combination of attributes) that uniquely identifies any
given row. In this case, STU_NUM (the student number) is the primary key.
194
Relational Data Model and the Relational Algebra (cont...)
Keys
In the relational model, keys are important b/c they are used to ensure that
each row in a table is uniquely identifiable. They are also used to establish
relationships among tables and to ensure the integrity of the data.
It consists of one or more attributes that determine other attributes. For
example, an invoice number identifies all of the invoice attributes, such as
the invoice date and the customer name.
The key’s role is based on a concept known as determination. In a
database table context, the statement “A determines B” indicates that if the
value of attribute A is know, it is possible to determine the value of attribute
B.
195
Relational Data Model and the Relational Algebra (cont...)
196
Relational Data Model and the Relational Algebra (cont...)
198
Relational Data Model and the Relational Algebra (cont...)
199
Relational Data Model and the Relational Algebra (cont...)
Super key is any key that uniquely identifies each row. In short,
the super key functionally determines all of a row’s attributes. Ex.
In the STUDENT table, the super key could be any of the
following:
STU_NUM
STU_NUM, STU_FNAME
201
Relational Data Model and the Relational Algebra (cont...)
205
Relational Data Model and the Relational Algebra (cont...)
206
Relational Data Model and the Relational Algebra (cont...)
207
Relational Data Model and the Relational Algebra (cont...)
Example
The link between the PRODUCT and VENDOR tables which indicated by the
line represent the relational diagram. And it is equivalent of the relationship line
in an ERD. This link is created when the two tables share an attribute with
common values. I.e. primary key of one table (VENDOR) appears as the
208
Relational Data Model and the Relational Algebra (cont...)
209
Relational Data Model and the Relational Algebra (cont...)
If the foreign key contains either matching values or nulls, the table
use of that foreign key is said to bet referential integrity. In other
words, referential integrity means that if the foreign key contains a
value, that value refers to an existing valid tuple (row) in another
relation. For example the referential integrity is maintained between
the PRODUCT and VENDOR tables
210
Relational Data Model and the Relational Algebra (cont...)
212
Relational Data Model and the Relational Algebra (cont...)
Integrity rules
Relational database integrity rules are very important to good database
design. Summary of integrity rules
213
Relational Data Model and the Relational Algebra (cont...)
214
Relational Data Model and the Relational Algebra (cont...)
215
Relational Data Model and the Relational Algebra (cont...)
216
Relational Data Model and the Relational Algebra (cont...)
218
Relational Data Model and the Relational Algebra (cont...)
220
Relational Data Model and the Relational Algebra (cont...)
221
Relational Data Model and the Relational Algebra (cont...)
222
Relational Data Model and the Relational Algebra (cont...)
• Properties of relational databases
– Each row of a table is uniquely identified by a primary key – w/c
composed to one or more columns.
– Each tuple in a relation must be unique
– Group of columns, that uniquely identifies a row in a table is called a
candidate key
– Entity integrity rule of the model- states that no component of the primary
key may contain a null value.
– A column or combination of columns that matches the primary key of
another table is called a foreign key- w/c used to cross-reference tables.
32
Relational Data Model and the Relational Algebra (cont...)
should be null.
33
Relational Data Model and the Relational Algebra (cont...)
– VIEWS are derived from BASE TABLES with SQL instructions like:
[SELECT .. FROM .. WHERE .. ORDER BY]
– Is the collection of tables
• Each entity in one table
• Attributes are fields (columns) in table
– Order of rows and columns is immaterial (irrelevant).
– Entries with repeating groups are said to be un-normalized
– Entries are single-valued
– Each column (field or attribute) has a distinct name
• All values in a column represent the same attribute and have the same data
format
34
Relational Data Model and the Relational Algebra (cont...)
35
The end
Thank you!!
227
Chapter- 4
1
Database Design(cont….)
Database design
− is the process of coming up with different kinds of specification for the
data to be stored in the database.
− consists of two parallel activities:
the first activity involves the design of the data content, structure, and
constraints of the database.
the second activity relates to the design of database applications.
2
Database Design(cont….)
3
Database Design(cont….)
Out of these, a database system can be focused on the Design part which
4
Database Design(cont….)
In developing a good database design, it needs to answer the following
What are the other requirements of the Organization and the Users.
5
Database Design(cont….)
1. The first activity is design conceptual schema w/c examines the data
requirements and produces a conceptual database schema .
2. The second activity is design transaction and application w/c examines
the database applications and produces high-level specifications for
these applications.
6
Database Design(cont….)
Its main goal is to produce a conceptual schema for the database that
is independent of a specific DBMS.
Mostly it uses a high-level data model such as the ER or EER model to
describe the data at this level.
it considered as an iterative refinement process until the most suitable
design is reached.
After the completion of Conceptual Design one has to go for refinement
of the schema, which is verification of Entities, Attributes, and
Relationships.
7
Database Design(cont….)
• Conceptual design revolves around discovering and analyzing
organizational and user data requirements
• The important activities are to identify:
– Entities
– Attributes
– Relationships
– Constraints
• And based on these components develop the ER model using :
– ER diagrams
10
Database Design and Normalization(cont….)
• Foreign key is a primary or candidate key of one relation used to create
association between tables.
• For a relationship with One-to-One Cardinality:
– post the primary or candidate key of one of the table into the other as a
foreign key.
11
Database Design and Normalization(cont….)
• Here the PK of the Employee can be posted to the Department
or the PK of the Department can be posted to the Employee.
• But the Employee is having partial participation on the
relationship "Manages" b/c not all employees are managers of
departments.
• So, it is recommended to post the primary key of the employee
to the department table as a foreign key.
• For a relationship with One-to-Many Cardinality:
– the primary key or candidate key from the “one” side Post
as a foreign key attribute to the “many” side. 12
Database Design and Normalization(cont….)
• E.g.: For a relationship called “Belongs To” between Employee
(Many) and Department (One) the primary or candidate key of
the one side such as the Department should be posted to the many
side which is Employee table.
• – For a relationship with Many-to-Many Cardinality:
14
Database Design and Normalization(cont….)
• Employee works for department.
organization.
registered.
15
Database Design and Normalization(cont….)
16
Database Design and Normalization(cont….)
• After drawn the ER diagram, the next step is map the ER into relational
schema, then the rules of the relational data model can be tested for each
relational schema.
• Mapping can be done for the entities followed by relationships based on
the rule of mapping.
it has been done as follows:
• Mapping EMPLOYEE Entity:
– i.e. Employee table with EID, Salary, FName and LName being the
columns.
– The composite attribute Name will be ignored as its decomposed
attributes (FName and LName) are columns in the Employee Table.
– The Tel attribute will be a new table as it is multi-valued.
17
Database Design and Normalization(cont….)
18
Database Design and Normalization(cont….)
• Mapping the MANAGES Relationship:
As the relationship is having one-to-one cardinality, the PK or CK of one
of the table can be posted into the other. But based on the recommendation,
the Pk or CK of the partial participant (Employee) should be posted to the
total participants (Department).
• So, adding the PK of Employee (EID) in the Department Table as a foreign
key. B/c of this another name give to the foreign key which is MEID, mean
"managers employee id".
• this will affect the degree of the Department table as follows:
19
Database Design and Normalization(cont….)
• Mapping the PARTICIPATES Relationship:
As the relationship is having many-to-many cardinality, it
need to create a new table and post the PK or CK of the
Employee and Project table into the new table. B/c of this a
descriptive new name give for the new table like:
• Emp_Partc_Project to mean "Employee participate in a
project".
20
Database Design and Normalization(cont….)
• Mapping the LEADS Relationship:
– As the relationship is associative entity, create a table for the
associative entity where the PK of Employee and Project tables will be
posted in the new table as a foreign key.
• So, the new table will have the attributes of the associative entity as
columns. B/c of this, a descriptive new name give for the new table like
Emp_Lead_Project to mean "Employee participate in a project".
21
Database Design and Normalization(cont….)
• At the end of the mapping, there is the following relational schema (tables)
for the logical design phase.
22
Database Design and Normalization(cont….)
• Example 2
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
Combined, these are a composite primary key
(uniquely identifies the order line)…
individually they are foreign keys (implement
M:N relationship between order and product)
23
Database Design and Normalization(cont….)
• Normalization
• Database normalization
– is a series of steps followed to obtain a database design that allows for
consistent data storage and efficient access of data in a relational
database.
– is the process of efficiently organizing data in a database with two
goals
– Such as :-
• to eliminate / reduce data redundancy
– for example, storing the same data in more than one table
• ensure data dependencies
Reduce risk of data becoming inconsistent. 24
Database Design and Normalization(cont….)
• NORMALIZATION
1. Insertion Anomalies
2. Deletion Anomalies
3. Modification Anomalies
25
Database Design and Normalization(cont….)
• Normalization is a formal process for deciding which attributes should be
grouped together in a relation
• Normalization:
– The process of decomposing unsatisfactory "bad" relations (with
anomalies) by breaking up their attributes into smaller relations.
– Primarily a tool to validate and improve a logical design so that it
satisfies certain constraints that avoid unnecessary duplication of
data
• Normal form:
– Condition using keys and FDs of a relation to certify whether a relation
schema is in a particular normal form
26
Database Design and Normalization(cont….)
• Normalization
– may reduce system performance since data will be cross referenced
from many tables.
– So, de-normalization is sometimes used to improve performance, at
the cost of reduced consistency guarantees.
• All the normalization rules will eventually remove the update anomalies
that may exist during data manipulation after the implementation.
• Update anomalies
– type of problems that occur in insufficiently normalized table.
– includes
27
Database Design and Normalization(cont….)
• Insertion anomalies
– An "insertion anomaly" is a failure to place information about
a new database entry into all the places in the database.
In a properly normalized database, information about a new entry
needs to be inserted into only one place in the database.
• Deletion anomalies
– A "deletion anomaly"
» is a failure to remove information about an existing
database entry when it is time to remove that entry.
In a properly normalized database, information about an old,
to-be-gotten-rid-of entry needs to be deleted from only one
place in the database
28
Database Design and Normalization(cont….)
• Modification anomalies
– A modification of a database involves changing
some value of the attribute of a table.
In a properly normalized database table, whatever
information is modified by the user, the change will
be effected and used accordingly.
• So, the purpose of normalization is to reduce the chances for
anomalies to occur in a database.
• Example of problems related with anomalies.
29
Database Design and Normalization(cont….)
30
Database Design and Normalization(cont….)
• Deletion Anomalies:
If employee with ID 16 is deleted then information about skill C++
and the type of skill is deleted from the database. Then, there is no any
information about C++ and its skill type.
• Insertion Anomalies:
If there is a new employee with a skill called Pascal. Impossible to
decide weather Pascal is allowed as a value for skill and no clue about
the type of skill that Pascal should be categorized as.
• Modification Anomalies:
if the address for Helico is changed from Piazza to Mexico.
It need to look for every occurrence of Helico and change the value of
School_Add from Piazza to Mexico, which is prone to error.
31
Database Design and Normalization(cont….)
Physical Database Design
Physical design
37
Database Design and Normalization(cont….)
• Physical database design
– is the process of producing a description of the implementation
of the database on secondary storage.
– describes the base relation, file organization, and indexes used
to achieve efficient access to the data, and any associated
integrity constraints and security measures.
Describes the storage structures and access methods used to
achieve efficient access to the data.
– is concerned with the how but Logical database design is
concerned with the what.
– Its Sources of information is logical data model and
documentation that describes model.
38
Database Design and Normalization(cont….)
• Steps in physical database design
39
Database Design and Normalization(cont….)
3. Design user view
4. Design security mechanisms
5. Consider controlled redundancy
6. Monitor and tune the operational system
information gathered.
40
Database Design and Normalization(cont….)
– It need to know functionality of target DBMS
• How
• its domain, its data type, length and any constraints on the domain;
• an optional default value for the attribute it the attribute can hold
nulls.
• Some DBMS provide more facilities than others for defining enterprise
constraints.
• Example:
CONSTRAINT StaffNotHandlingTooMuch
CHECK (NOT EXISTS (SELECT staffNo
FROM PropertyForRent
GROUP BY staffNo
To understand the functionality of the transactions that run on the database and
to analyze the important transactions.
44
Database Design and Normalization(cont….)
– Attempt to identify :
relations.
45
Database Design and Normalization(cont….)
Choose file organizations
46
Database Design and Normalization(cont….)
– Another approach is to order tuples in the relation by specifying a
primary or clustering index.
– In this case, choose the attribute for ordering or clustering the tuples as:
• attribute that is used most often for join operations - this makes
join operation more efficient, or
• attribute that is used most often to access the tuples in a relation in
order of that attribute.
– If ordering attribute chosen is key of relation, index will be a primary
index; otherwise, index will be a clustering index.
– Each relation can only have either a primary index or a clustering
index.
– Secondary indexes provide a mechanism for specifying an additional
key for a base relation that can be used to retrieve data more efficiently.
47
Database Design and Normalization(cont….)
• Estimate disk space requirements
– To estimate the amount of disk space that will be required by the
database.
• Design User Views
– To design the user views that were identified during the Requirements
Collection and Analysis stage of the database system development
lifecycle.
• Design Security Measures
– To design the security measures for the database as specified by the
users.
48
Database Design and Functional Dependency
• Functional Dependency (FD)
– Before definition application of normalization, it need understand
"functional dependency."
• Data Dependency
– The logical associations between data items which point database
designer in the direction of a good database design are referred as
determinant or dependent relationships.
• Functional Dependency (FD)
– Two data items A and B are said to be in dependent relationship if
certain values of data item B always appears with certain values of data
item A.
49
Database Design and Functional Dependency(cont….)
– The notation is: A → B which is read as; B is functionally
dependent on A.
– A → B holds if whenever a given tuple has the same value for
A, it must have the same value for B.
50
Database Design and Functional Dependency(cont….)
• Partial Dependency
– If an attribute which is not a member of the primary key is
dependent on some part of the primary key (if it has
composite primary key) then that attribute is partially
functional dependent on the primary key.
• Example:
– Let {A,B} is the Primary Key and C is no key
attribute.
– Then if {A,B} → C and B --> C
– Then C is partially functional dependent on {A,B}
51
Database Design and Functional Dependency(cont….)
• Full Dependency
– If an attribute which is not a member of the primary key is
not dependent on some part of the primary key but the
whole key (if it has composite primary key) then that
attribute is fully functionally dependent on the primary
key.
• Let {A,B} is the Primary Key and C is no key attribute
• Then if {A,B} → C and B → C and A → C does hold
52
Database Design and Functional Dependency(cont….)
Transitive Dependency
– Example:
53
Database Design and Normalization(cont….)
• Steps in Normalization
when move from one lower level Normal Form to the higher.
1. Un-normalized Form:
54
Database Design and Normalization(cont….)
2. First Normal Form:
whole key.
55
Database Design and Normalization(cont….)
• First Normal Form (1NF)
– If so then Find the key with which you can find all data.
56
Database Design and Normalization(cont….)
• Definition: A table (relation) is in 1NF
– If:
• There are no duplicated rows in the table. Unique
identifier
• Each cell is single-valued (i.e., there are no repeating
groups).
• Entries in a column (attribute, field) are of the same
kind.
• Example for First Normal form (1NF )
57
Database Design and Normalization(cont….)
58
Database Design and Normalization(cont….)
• FIRST NORMAL FORM (1NF)
– Remove all repeating groups.
59
Database Design and Normalization(cont….)
• Second Normal form 2NF
– This will result in a set of relations with a level of Second Normal Form.
– If:
• It is in 1NF and
• If all non-key attributes are dependent on the entire primary key. i.e.
no partial dependency.
60
Database Design and Normalization(cont….)
• Example for 2NF:
61
Database Design and Normalization(cont….)
– {EmpID, ProjNo} -->EmpName, ProjName, ProjLoc,
ProjFund, ProjMangID, Incentive.
• But in addition to this we have the following dependencies:
– FD1: {EmpID}--> EmpName
63
Database Design and Normalization(cont….)
• Third Normal Form (3NF )
– Eliminate Columns Dependent on another non-Primary Key.
– If attributes do not contribute to a description of the key, remove
them to a separate table.
– This level avoids update and delete anomalies.
• Definition: a Table (Relation) is in 3NF
– If :
• It is in 2NF and
• There are no transitive dependencies between a primary key and
non-primary key attributes.
64
Database Design and Normalization(cont….)
• Example for (3NF)
– Assumption: Students of the same batch (the same year) live in one
building or dormitory.
65
Database Design and Normalization(cont….)
– This schema is in its 2NF since the primary key is a single attribute.
– Let’s take StudID, Year and Dormitory and see the dependencies.
– StudID --> Year AND Year Dormitary
67
Database Design and Normalization(cont….)
• Generally, even though there are other four additional levels of
Normalization, a table is said to be normalized if it reaches 3NF.
• A database with all tables in 3NF is said to be Normalized Database.
• Mnemonic for remembering the underlying principle for normalization up
to 3NF can be the following:-
– No Repeating or Redundancy: no repeating fields in the table.
– The Fields Depend Upon the Key: the table should solely depend on
the key.
– The Whole Key: no partial key dependency.
– And Nothing But The Key: no inter data dependency.
– So Help Me Codd: since Codd came up with these rules.
68
Database Design and Normalization(cont….)
• Graphical illustration of different phases of normalization
69
Database Design and Normalization(cont….)
• Benefits of Normalization
– Less storage space
– Quicker updates
– Less data inconsistency
– Clearer data relationships
– Easier to add data
– Flexible Structure
70
Database Design and Normalization(cont….)
• Drawbacks of Normalization
– Requires data to see the problems
– May reduce performance of the system
– Is time consuming,
– Difficult to design and apply and
– Prone to human error
70
The end
Thank you!!!
71
Lab (chapter -6)
SQL
(structured Query Language)
1
Introduction to SQL
SQL
3
Introduction to SQL(cont……)
SQL query
– includes references to tuples variables and the attributes of those
variables
– is a comprehensive database language that includes statements for data
definition, queries, updates, constraint specification, and view
definition.
. Hence, it is both a DDL and a DML
i.e. It includes
data definition language (DDL) – which is statements that specify and
modify database schemas.
data manipulation language (DML)- which is statements that
manipulate database content.
3
Introduction to SQL(cont…)
• Also it has facilities for defining views on the database, for
specifying security and authorization, for defining integrity
constraints, and for specifying transaction controls.
• It also has rules for embedding SQL statements into a general-
purpose programming language such as Java, COBOL, C# or
C/C++.
• Generally SQL and its variations have been implemented as
interfaces to many commercial relational DBMSs, including
Microsoft’s SQL Server and Access, Oracle’s and Relational db.
4
Introduction to SQL(cont…)
SQL
5
Introduction to SQL(cont…)
CREATE TABLE Statement
Things to consider before create table are:
type of data
table name
what column(s) will make up the primary key
names of the columns
CREATE statement syntax:
• CREATE TABLE <table name>
• ( field1 datatype ( NOT NULL ),
• field2 datatype ( NOT NULL )
• );
6
SQL: Attributes Types
7
Introduction to SQL(cont…)
ALTER TABLE Statement
To add or drop columns on existing tables.
ALTER TABLE statement syntax:
• ALTER TABLE <table name>
8
Introduction to SQL(cont…)
• DROP TABLE Statement
– Has two options:
9
Introduction to SQL(cont…)
• Example:
FoodCart
• CREATE TABLE FoodCart (
• date varchar(10), date food profit
• food varchar(20),
• profit float
• ); FoodCart
10
Introduction to SQL(cont…)
DML Commands
INSERT: adds new rows to a table.
UPDATE: modifies one or more attributes.
DELETE: deletes one or more rows from a table.
11
Introduction to SQL(cont…)
INSERT Statement
To insert a row into a table, it is necessary to have a value for each attribute, and
order matters.
Food chart
date food sold date food sold
02/25/08 Pizza 350 02/25/08 Pizza 350
02/26/08 Sandwich 500 02/26/08 Sandwich 500
02/26/08 Pizza 70
12
Introduction to SQL(cont…)
UPDATE Statement
• Food cart
date food sold date food sold
02/25/08 Pizza 350 02/25/08 Pizza 349
02/26/08 Sandwich 500 02/26/08 Sandwich 500
02/26/08 Pizza 70 02/26/08 Pizza 70
13
Introduction to SQL(cont…)
DELETE Statement
To delete rows from the table:
• DELETE statement syntax:
– DELETE FROM <table name>
– WHERE <condition>;
• Example: DELETE FROM FoodCart
WHERE food = ‘Sandwich’;
• Food cart
14
Introduction to SQL(cont…) SQL
SQL - Statements, Operations, Clauses
SQL Statements:
Select
SQL Operations:
Join
Left Join
Right Join
Like
SQL Clauses:
Order By
Group By
Having 15
Introduction to SQL(cont…)
SELECT Statement
A basic SELECT statement includes 3 clauses
• SELECT <attribute name> FROM <tables> WHERE <condition>
• SELECT
– Specifies the attributes that are part of the resulting relation
• FROM
– Specifies the tables that serve as the input to the statement
• WHERE
– Specifies the selection condition, including the join condition.
• Note: that you don't need to use WHERE
16
Introduction to SQL(cont…)
SELECT Statement
Using a “*” in a select statement indicates that every attribute of the input
table is to be selected.
• Example: SELECT * FROM … WHERE …;
To get unique rows, type the keyword DISTINCT after SELECT.
• Example: SELECT DISTINCT * FROM … WHERE …;
17
• Example:
• Person 2) SELECT weight FROM person
WHERE age > 30;
Name Age Weight Weight
Harry 34 80 80
Sally 28 64 54
George 29 70
80
Helena 54 54
Peter 34 80
1) SELECT * 3) SELECT distinct weight
FROM person FROM person
WHERE age > 30; WHERE age > 30;
18
Introduction to SQL(cont…)
Join operation
A join can be specified in the FROM clause which list the two input
relations and the WHERE clause which lists the join condition.
Example:
Emp Dept
ID State ID Division
1000 CA 1001 IT
1001 MA 1002 Sales
1002 TN 1003 Biotech
19
Introduction to SQL(cont…)
Join operation
inner join = join
SELECT *
on emp.id = dept.id;
20
Introduction to SQL(cont…)
Join operation
SELECT *
on emp.id = dept.id;
Emp.ID Emp.State Dept.ID Dept.Division
1000 CA null null
1001 MA 1001 IT
1002 TN 1002 Sales
21
Introduction to SQL(cont…)
Join operation
SELECT *
on emp.id = dept.id;
Emp.ID Emp.State Dept.ID Dept.Division
1001 MA 1001 IT
1002 TN 1002 Sales
null null 1003 Biotech
22
Introduction to SQL(cont…)
Like operation
% (arbitrary string)
SELECT *
FROM emp
23
Introduction to SQL(cont…)
_ (a single character)
SELECT *
FROM emp
finds ID that has the second and third character as 01, e.g. 1010,
1011, 1012, 1013, etc
24
Introduction to SQL(cont…)
• The ORDER BY Clause
Ordered result selection
SELECT *
FROM emp
25
Introduction to SQL(cont…)
asc (ascending order)
SELECT *
FROM emp
order by id asc
26
Introduction to SQL(cont…)
The GROUP BY Clause
The function to divide the tuples into groups and returns an aggregate for
each group.
Usually, it is an aggregate function’s companion
• FROM FoodCart
• group by food;
• FoodCart
date food sold food Total sold
•
02/25/08 Pizza 349 Sandwich 500
02/26/08 Sandwich 500 Pizza 419
02/26/08 Pizza 70
27
Introduction to SQL(cont…)
FROM FoodCart
group by food
29
Introduction to SQL(cont…)
• Food cart
date food sold
02/25/08 Pizza 349
02/26/08 Sandwich 500
02/26/08 Pizza 70
COUNT(attr) -> return # of rows that are not null
Ex: COUNT(distinct food) from FoodCart; -> 2
SUM(attr) -> return the sum of values in the attr
Ex: SUM(sold) from FoodCart; -> 919
MAX(attr) -> return the highest value from the attr
Ex: MAX(sold) from FoodCart; -> 500
30
Introduction to SQL(cont…)
• Food cart
31
The end
Thank you!!!
32