You are on page 1of 68

Database Systems

Paul Danquah
Essence of Database Systems
• Many computing applications deal with large amounts of information

• Database systems give a set of tools for storing, searching and


managing this information

• Databases are a ‘core topic’ in Information Technology

• Basic concepts and skills with database systems are part of the skill
set you will be assumed to have as an IT graduate
Database Terminologies
• Data: term data refers to raw facts and figures, such as orders and
payments

• Data represent the values physically recorded in the Database; e.g. 10023

• Info: processed data into meaning, such as balance due and quantity on
hand Information, though, refers to the meaning of those values as
understood by some users
• e.g. Mohammed’s Employee number is 10023
Database Terminologies
• DBMS: Software used to create or maintain these database tables

• Data administrator (DA) is the chief person who oversees and


manages all data resources with the organization

• Database administrator (DBA) is responsible for the physical


actualization of the Database
What is a Database?
• “A set of information held in a computer”
Oxford English Dictionary

• “One or more large structured sets of persistent data, usually


associated with software to update and query the data”
Free On-Line Dictionary of Computing

• “A collection of data arranged for ease and speed of search and


retrieval”
Dictionary.com
What is a Database?
• The Database is a collection of related data. They must be related,
otherwise there is no context in the data and the data becomes
useless

• The definitions of all data in the DB are called Meta-data (data about
data) and it is stored in a Data Dictionary (DD)
Database Systems
• Database
A databasesystems
systemallow
consists
users
of to
• Data (the database)
•• Software
Store
•• Hardware
Update
•• Users
Retrieve
• Organise
• Protect

• We focus mainly on the software


their data.
Database Users
• End users • Database Administrator
• Use the database system to (DBA)
achieve some goal • Designs & manages the
database system

• Application developers
• Write software to allow end
users to interface with the • Database systems
database system
programmer
• Writes the database
software itself
Exhibit Interaction Between the User, DBMS
and Database

Copyright ©2016 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. MIS5 | CH3 9
Database Management Systems
• Examples of DBMS:
• Oracle
• A database is a collection of information • DB2 (IBM)
• MS SQL Server
• MS Access
• Ingres
• A database management system (DBMS) is • PostgreSQL
the software than controls
that information • MySQL
What the DBMS does;
• DBMS
Provides
provides
users with
• Persistence
•• Concurrency
Data definition language (DDL)
•• Integrity
Data manipulation language (DML)
•• Security
Data control language (DCL)
• Data independence

• Data Dictionary
• Often these the
• Describes aredatabase
all the same
itself language
Components of a DBMS

Database engine

Data definition

Data manipulation

Application generation

Data administration
Database Engine
• Heart of DBMS software

• Responsible for data storage, manipulation, and


retrieval

• Converts logical requests from users into their


physical equivalents
• By interacting with other components of the DBMS
Data Definition
• Creates and maintains the data dictionary

• Defines the structure of files in a database

• Makes changes to a database’s structure


• Adding and deleting fields
• Changing field size and data type
Data Manipulation
• Used to add, delete, modify, and retrieve records
from a database

• Uses a query language


• Structured Query Language (SQL)
• Standard fourth-generation query language that consists of
several keywords specifying actions to take
• Query by example (QBE)
• Involves requesting data from a database by constructing a
statement formed by query forms
Application Generation
• Designs elements of an application using a
database
• Data entry screens
• Interactive menus
• Interfaces with other programming languages

• Used by IT professionals and database


administrators
Data Administration
• Used for the tasks backup and recovery, security,
and change management
• Used to determine who has permission to perform
certain functions
• Summarized as create, read, update, and delete
(CRUD)
Data Administration
• Database administrator (DBA)
• Handles database design and management
• Setting up database
• Establishing security measures to determine users’ access rights
• Developing recovery procedures when data is lost or corrupted
• Evaluating database performance
• Adding and fine-tuning database functions
Data Dictionary - Metadata
• The dictionary holds
or catalog stores information about the database itself

• Descriptions
• This of database
is data about data orobjects (tables, users, rules, views, indexes,…)
‘metadata’

• Information about who is using which data (locks)


• Almost every aspect of the DBMS uses the dictionary
• Schemas and mappings
File Based Systems
• Disadvantages:
•-The
Filesharing of data among
Based Storage (Pre-DBvarious applications (e.g. using customer details on
Systems)
sales and marketing). The problem here is of data ownership. Who owns the data?
• These files were separate and not
-Incross-indexed;
typical business applications,
such user requirements may change or evolve over time
"stand-alone"
files are sometimes called flat files
File Based Systems
• Problems:
File based systems

• No
Datastandards
is stored in files

• Data
Each duplication
file has a specific format

• Programs
Data dependence
that use these files depend
on knowledge about that format
• No way to generate ad hoc queries

• No provision for security, recovery, concurrency, etc.


Problems with Using Flat Files

• - When a file grows large, working with it can be very slow.

• - Searching for a particular record or group of records in a flat file is difficult.

• - Dealing with concurrent access can become problematic

• - Beyond the limits offered by file permissions, there is no easy way of


enforcing different levels of access to data.
How RDBMSs Solve These Problems

• - RDBMSs can provide much faster access to data than flat files.

• - RDBMSs can be easily queried to extract sets of data that fit certain criteria.

• - RDBMSs have built-in mechanisms for dealing with concurrent access so that you, as a
programmer, don’t have to worry about it.

• - RDBMSs provide random access to your data.

• - RDBMSs have built-in privilege systems. MySQL has particular strengths in this area.
Lifecycle of Database System Development
Relational Systems
• Problems with early databases • Then, in 1970, E. F. Codd
wrote “A Relational Model of
• Navigating the records requires
Data for Large Shared Databanks”
complex programs and introduced the relational
model
• There is minimal data
independence

• No theoretical foundations
Relational Systems
• The Database approach rests • Database processing involves
upon the concept of the modern assembling the data contained in
database which is formally the tables into a form that is
defined as an integrated, self- suitable for the end-user's
particular application needs.
describing collection of related
records organized into files
which are often referred to as
database tables.
Relational Systems
• Information is stored as tuples • The relational model covers 3
or records in relations or tables areas:

• There is a sound mathematical • Data structure


theory of relations
• Data integrity

• Most modern DBMS are based


on the relational model • Data manipulation
Database Models

• A model is a set of concepts used to represent some aspects, one or


more, of a UoD, domain or area of interest, of some requirement;

• It is an abstraction of the important things in the domain. A model is a


high abstract perception of the domain
Relational Model
• Uses a two-dimensional table of rows and columns
of data

• Rows are records/tuples

• Columns are fields


Relational Model
• Primary key

• Uniquely identifies every record in a relational database

• Foreign key

• Field in a relational table that matches the primary key


column of another table

• Used to cross-reference tables


Relational Model
• Normalization
• Improves database efficiency by eliminating redundant
data
• Ensures that only related data is stored in a table

• Goes through different stages from first normal form


(1NF) to fifth normal form (5NF)
Database Modelling
• Building a good data model depends on the process of data analysis.

The objectives of data analysis are two folds:

• Investigate the "Natural Structure" of the information to be stored, i.e.


deciding exactly what the relationships are between individual datum.

• Produce a representation (or model) of that structure, which will be


suitable for easy conversion into a database structure description (schema).
Database Models
• Conceptual data model (High-Level):
It provides concepts that are close to the way many users perceive data (e.g. ERD). It is a
set-based data model and DBMS independence.
Data abstraction frees the Database designer or developer from any physical details

• Representational data model (Implementation):


It provides concepts that are understood by end users but that are not too far
removed from the way data is organized within the computer. It is also called
Logical Data Model.

• Physical model (low-level):


It provides concepts that describe details of how data is stored in the computer (e.g.
Access paths & data structures). Concepts provided by low-level data model are generally
meant for computer specialists, not for typical users.
Disadvantages of Modelling
• Complexity

• Size

• Higher impact of failure

• Cost of DBMS

• DBMS Size
Entity-Relationship Model concepts
• Top-down Approach
- Identify data entities
- Determine attributes of the entities
- Determine the nature of the relationships

• Bottom-up Approach
- Gather information on data used by the organization by examining
current files and evaluating existing reports and forms
- Group gathered information into Entities and Attributes
- Identify relationship and determine their nature.
Entity-Relationship Model concepts
• Entity

• Attributes

• Relationship

• Constraints

• Cardinality

• Dependencies

• Primary, Foreign and Composite Keys


Entity Relation Diagram (Chen notation)
Entity Relation Diagram
Entity Relation Diagram
Structured Query Language (SQL)

• Introduction to SQL

• Basic structure of SQL commands

• Data Definition

• Data Manipulation

• Aggregation
Introduction to SQL

• An ISO standard now exists for SQL, making it both the formal and de
facto standard language for relational databases

• SQL is a transform-oriented language with two major components

• These are the DDL for defining the database structure

• DML for retrieving and updating data


Basic Structure of SQL commands

• SQL statement consists of reserved words and user-defined words


Reserved Words such SELECT, UPDATE, DELETE etc …

• User-defined words are made up by user and represent names of


various database objects such as relations, columns and views
Data Definition / Data Declarative
Data Definition
DATA DECLARATION
STATEMENTS
Creating Tables and Databases

Creating Tables
CREATE TABLE table;

Creating a Whole Database


CREATE DATABASE database;
Dropping, Altering Tables
and Databases

Dropping Tables
DROP TABLE table;

Dropping a Whole Database


DROP DATABASE database;

ALTER TABLE `testing` DROP `testing_author`


DATA DECLARATION STATEMENTS
CREATE TABLE `articles` (
`article_id` int(11) NOT NULL AUTO_INCREMENT,
`article_title` text NOT NULL,
`article_content` longtext NOT NULL,
`article_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`article_author` varchar(15) DEFAULT NULL,
PRIMARY KEY (`article_id`) ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT
CHARSET=latin1 CHECKSUM=1

DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC;
Output of Command
Table created called "articles"
Fields are

"article_id" the primary key


"article_title"
"article_content"
"article_date"
"article_author"
DATA MANIPULATION
STATEMENTS
Working with Databases
INSERT
INSERT [INTO]table[(column1,column2,column3,...)] VALUES
(value1,value2,value3,...);

For example,to insert a record into Book-O-Rama’s customers table,you could type

insert into customers values (NULL, 'Julie Smith', '25 Oak Street', 'Airport West');
’’’
SELECT

select name, city from customers;


Retrieving Data with Specific Criteria

WHERE clause

• select * from orders where customerid = 3;


Retrieving Data from Multiple Tables

select orders.orderid, orders.amount, Orders.date


from customers, orders
where customers.name =‘Julie Smith’
and customers.customerid = orders.customerid;
Using Other Names for Tables: Aliases

select c.name
from customers as c, orders as o, order_items as oi, books as b
where c.customerid = o.customerid
and o.orderid = oi.orderid
and oi.isbn = b.isbn
and b.title like ‘%Java%’;
Retrieving Data in a Particular Order

select name, address from customers


order by name;
Data Manipulation: 1
Data Manipulation: 2
Data Manipulation: 3
Data Manipulation: 4
Data Manipulation: 5
Data Manipulation: 6
SQL Case Study
Normalization for Relational Databases

• Functional Dependency: is the key factor for grouping attributes in


one relation

• A series of formal tests on a relation to determine whether it


satisfies or violates the requirements of a given normal form

• The objective of this process is to separate the data (attribute values)


into sets based functional dependencies between attributes.
Normalization for Relational Databases

Topics:

• First Normal Form (1NF)

• Second Normal Form (2NF)

• Third Normal Form (3NF)

• Boyce-Codd Normal Form (BCNF)


Purpose of Normalization

Using formal methods to separate the data into multiple related tables

A large number of tables with few columns

A database with only few tables and many columns is indicative of an


un-normalised or partially normalised database.

Benefits of a normalised relation include faster sorting and index


creation, larger number of clustered indexes, narrower and more
compact indexes
Purpose of Normalization

Normalization aims to avoid redundant duplication

Reduces the opportunity for database inconsistency

Fewer null values for data that is either not required or not known

The side effect of normalization is that as it is implemented the number


and complexity of joins required to retrieve data is increased. Too many
complex relational joins between many tables can degrade
performance

You might also like