Database Management System Chapter One
Database Management System Chapter One
Systems
• Database
• Database system
• Database-System Applications
6-3
Information and Knowledge
• Information is the processed data presented in a form suitable for
human interpretation.
• Information is the result of processing raw data to reveal its meaning.
• Knowledge:
6-4
Database
• A database is an organized collection of interrelated data, generally
stored and accessed electronically from a computer system.
• It contains information relevant to an enterprise.
• Management of data involves both defining structures for storage of
information and providing mechanisms for the manipulation of information.
• The database is an important assets for many organizations.
1-5
Database (Cont.)
• The database is an integrated collection of facts about an organization.
• Organization can be a University or a department in a University , Insurance companies,
Manufacturing companies, Banks, Airlines, Telecommunications, Governmental and Non-
governmental Organizations, Research institutions ,etc.
1-6
Database (Cont.)
• A database can be defined accurately using its basic implicit properties:
– It represents some aspects of the Mini-world
– Any assortment of data is not a data base.
– It is a collection logically coherent data
1-7
Database Management System
• Database Management System is a program or software which is used to construct, manipulate and retrieve the data
in the database.
• A database management system (DBMS) is a collection of usually complex pieces of software that allows a user to
• The primary goal of a DBMS is to provide a way to store and retrieve database information that is both convenient
and efficient.
1-8
Database Systems
• A database system is a collection of interrelated data and a set of
programs that allow users to access and modify these data.
• Database systems are used to manage collections of data that are:
– Highly valuable,
1-9
Database Systems (Cont’d…)
• A modern database system is a complex software system whose task
1-10
Database Applications Examples
Here are some of the applications of database system
• Enterprise Information
– Sales: customers, products, purchases
– Accounting: payments, receipts, assets
– Human Resources: Information about employees, salaries, payroll
taxes.
• Manufacturing: management of production, inventory, orders, supply
chain.
• Banking and finance
– customer information, accounts, loans, and banking transactions.
– Credit card transactions
– Finance: sales and purchases of financial instruments (e.g., stocks
and bonds; storing real-time market data
• Universities: registration, grades
1-11
Database Applications Examples (Cont.)
– Online advertisements
• Document databases
13 1-13
Purpose of Database Systems (Cont.)
• Atomicity of updates
– Failures may leave database in an inconsistent state with partial updates carried out
– Example: Transfer of funds from one account to another should either complete or
not happen at all
• Concurrent access by multiple users
– Concurrent access needed for performance
– Uncontrolled concurrent accesses can lead to inconsistencies
• Ex: Two people reading a balance (say 100) and updating it by withdrawing
money (say 50 each) at the same time
• Security problems
– Hard to provide user access to some, but not all, data
14 1-14
Example University Database
• Mini-world for a University Database example: Part of a
UNIVERSITY environment.
• Some mini-world entities:
– STUDENTs
– PRE-REQUISITE COURSEs
– COURSEs
– DEPARTMENTs
– INSTRUCTORs
15
University Database Example
16
Example University Database(Continued…)
• Some mini-world relationships:
– STUDENTs take COURSEs
– COURSEs have PRE-REQUISITE COURSEs
– INSTRUCTORs teach COURSEs
– COURSEs are offered by DEPARTMENTs
– STUDENTs major in DEPARTMENTs
17
Example Relational Database Snapshot
18
Evolution of Database Systems
• Two approaches to convert data to information:
– File-based
• Developed starting from 1960’s
• Stores, manipulates, retrieves data from large flat files
– Database (relational systems)
• Developed by E. F. Codd of IBM the early 1980's
• Widely used today
Evolution of Database
Systems
19
File-Based Approach
• A file is a collection of related information
• A system of files and collection of application programs manipulating them is
a file-based system
20
Limitations of File-Based Approach
• Other limitations:
– Duplication of data
– Data dependency
21
Database Users and Administrators
– database users or
• Naïve users
• Application programmers
• Sophisticated users
– database administrators.
1-22
Database users
• Naive users are unsophisticated users who interact with the system
applications.
• The typical user interface for naive users is a forms interface, where
• Naive users may also view read reports generated from the database.
1-23
Database users
• Application programmers are computer professionals who write application programs.
Application programmers can choose from many tools to develop user interfaces.
• Sophisticated users interact with the system without writing programs. Instead, they
form their requests either using a database query language or by using tools such as
Analysts who submit queries to explore data in the database fall in this category.
1-24
Database Administrator
A person who has central control over the system is called a database
administrator (DBA). Responsibilities of a DBA include:
Schema definition
Routine maintenance
Ensuring that enough free disk space is available for normal operations, and
upgrading disk space as required
Monitoring jobs running on the database
1-25
Responsibilities of DBA
Schema definition.
The DBA creates the original database schema by executing a set of data
definition statements in the DDL.
1-26
Responsibilities of DBA (Cont’d.)
database system consults whenever a user tries to access the data in the
system.
1-27
Responsibilities of DBA (Cont’d.)
• Routine maintenance.
Monitoring jobs running on the database and ensuring that performance is not
degraded by very expensive tasks submitted by some users.
1-28
Fundamentals of Database Systems
! !
!
n e
o
e r
p t
h a
C
of
n d
E
1-29
Data Base System Concepts
and Architecture
Outline
User-defined operations
2.1.1 Categories of Data Models
Conceptual (high-level, semantic) data models: Provide concepts
that are close to the way many users perceive data. (Also called
entity-based or object-based data models.)
Entities
Attributes
Relationships
Physical (low-level, internal) data models: Provide concepts that
describe details of how data is stored in the computer.
Record formats
Record ordering
Access paths
2.1.1 Categories of Data Models (Continued…)
Schema Constructs
The UNIVERSITY database
Differentiating Schema and Instances
Database architecture: is a set of specifications , rules and processes that determine how
the database is designed and constructed. It also determines how data is stored in the
database and how data is accessed by the components of DBMS
schema into a request against the conceptual schema, and then into a request
against the internal schema for processing over the stored database
These mappings might be time consuming. So some DBMSs- specially those that
APPLICATION
DBA Staff Casual users PROGRAMS
Precompiled
execution
Concurrency Control/
Stored Data Manager Backup/Recovery Subsystems
STORED DATABASE
2.4 Software Modules of the DBMS
Access to the disk is controlled primarily by the operating system
(OS), which schedules disk input/output
Stored data manager module of the DBMS controls access to DBMS
information that is stored on disk, whether it is part of the database
or the catalogue. Note the dotted lines and circles
Stored data manager uses basic services of the OS to perform low-
level data transfer between hard disk and main memory
Other task of Stored data manager: Handling buffers in main memory
2.4 Software Modules of the DBMS
The DDL compiler processes schema definitions, specified in the DDL, and
stores the schema definitions (meta-data) in the DBMS catalogue
The run-time database processor handles database accesses at run time
under the supervision of stored data manager
It receives retrieval or update operations and carries them out on the
database
The query compiler handles high-level queries that are entered interactively
2.4 Software Modules of the DBMS
A centralized DBMS can support multiple users, but the DBMS and the
database themselves reside totally at a single computer site
Data Dumb
Terminal n
2.5 Centralized & Client/Server architecture for DBMS
A distributed DBMS (DDBMS) can have the actual database and DBMS
MYSQL
ENNTT
MYSQL
LAN
Mekelle Adigrat
MYSQL
ENNTT
MYSQL
LAN
Axum Adwa
Heterogeneous DDBMSs
DB 2
MYSQL
ENNTT
LAN
Mekelle Adigrat
ACCESS
MS
ORACLE
ENNTT
LAN
Axum Adwa
2.5 Centralized & Client/Server architecture for
DBMS
2.5.2 Client/Server architecture for DBMS
A client is defined as a requester of services and a server is defined as
A service can be any resource such as data, display device, CPU time,
memory, etc.
software configuration
Characteristics of a client
Initiates requests
Waits for replies
Receives replies
Usually connects to a small number of servers at one time
Typically interacts directly with end-users using a graphical user interface
Characteristics of a server
Never initiates requests or activities
Waits for and replies to requests from connected clients
A server can remotely install/uninstall applications and transfer data to the
intended clients
2.5 Centralized & Client/Server
architecture for DBMS
Two-tier Client/Server Architecture
It contains a client and a server
The DBMS & database are stored on the server, and the interface used to
access the database is installed on the client
An interface called Open Data Base Connectivity (ODBC) provides
Application Program Interface (API) that enables clients to call the DBMS
Server
Client DBMS
User Interface
= Request
Data
Two-tier Client/Server
Over a Communication Network
CLIENT 1
#1 SERVE
R
1
CLIENT D/BASE
#2
CLIENT
#3
Data Request
Data Response
2.5 Centralized & Client/Server
architecture for DBMS
Usage Considerations
Used extensively in non- time critical information processing where
management and operations of the system are not complex
Stores the web connectivity software and the rules and business logic
(constraints) part of the application used to access the right amount of
data from the database server
Acts like a conduit for sending partially processed data between the
database server and the client
Encryption and decryption of data for transmission between the client &
server
2.5 Centralized & Client/Server
architecture for DBMS
The 3-tier architecture
IIS=Internet Information Server
IIS is a web server developed by
Microsoft
It is the 2nd most popular web
server next to Apache HTTP
Server
2.5 Centralized & Client/Server
architecture for DBMS
The thin-client 3-tier model has these tiers:
The database management system (DBMS)
The main application software
A web browser
IT students in their web design course :
Database tier: MySQL
Middle tier: PHP/HTML
Client tier: Your favorite web browser
The thick-client 3-tier model has these tiers:
The database management system (DBMS)
The main application software
Some sort of interface software which must be installed on each
client machine
2.5 Centralized & Client/Server
architecture for DBMS
Advantages of the 3-tier architecture
Removes a huge processing burden from client machines
Any knowledge of the database server may be hidden from the client.
database queries may be presented to client in alternative forms
• SQL Statements
• SQL Constraints
• SQL functions
6-78
Introduction to SQL
• The full form of SQL is Structured Query Language
1-79
Introduction to SQL (Contd.)
• SQL is ANSI standard: American National Standards Institute
Standard
• SQL is composed of commands that enable users to create database
and table structures, perform various types of data manipulation and
data administration, and query the database to extract useful
information.
• SQL is a standard way to query/ obtain/ add/delete/modify the data
in a database.
1-80
Introduction to SQL (Contd.)
• SQL used by Academician’s, Data Scientist, Machine
learning Engineers, Software Engineers, etc.
• SQL is not general purpose programming language, like
C/C++/JAVA/Python, are general purpose programming
languages.
• SQL is called Domain Specific language, because SQL
is only useful in the domain of databases.
1-81
Introduction to SQL (Contd.)
• Its primarily task is way to query/ obtain/
add/delete/modify the data efficiently
• SQL is a declarative programming language,
means you DONOT have to define step by step
procedures to get something, instead just, focus
on: what you want, not how to get it?
1-82
SQL Statements
• SQL Statements play a major role in interacting with the database
• SQL statement is the smallest standalone element that expresses
some actions to be carried out.
• A syntax is how the keyword, identifiers and constants are
combined to from a valid statement
• SQL statements are made up of special words Keywords,
Identifiers, Constants, and Clauses
• SQL is not case sensitive, “select ” and “SELECT” are same.
• To distinguish keywords in a statement, all keywords should be
written in uppercase letters
• Semicolon (;) is required at the end of every SQL statement
1-83
SQL Statements (Contd.)
• Keywords: SQL standard words used to
construct the SQL statement. Some keywords
are optional, while some are mandatory
• Identifiers: Names we give to the database,
tables or columns
• Constants: Literals representing fixed values
• Clauses: portion of an SQL statement
1-84
SQL Statements (Contd.)
• Example: SELECT fname FROM students WHERE
studentid=5;
• KEYWORDS: SELECT,FROM & WHERE (optional)
• Keyword (operator): Equal sign (=)
• Identifiers: fname,students, and studentid
– Fname and studentid are column names
– Students is a table name
• Constant: numeric constant 5
• Clauses: SELECT, FROM, and WHERE clauses
1-85
SQL Statements (Contd.)
• SQL statements are used to manage the database from a
webpage or application, users interact with the database using
form fields.
• SQL statements are dived into two types
– 1. Data Definition Language (DDL)
– 2. Data Manipulation Language (DML)
• DDL and DML, both are SQL statements
• The best way to distinguish between DDL and DML is, by the
type of the SQL statement used and their effect on the database
• DDL changes the database structure, while DML changes only
the data
1-86
Data Definition Language (DDL)
• Data Definition Language is used to specify the database
schema
• Data Definition Language is used to manage database objects
like tables, columns, indexes and views.
• DDL changes the database structure
• Database objects like tables, columns, are created, modified,
or removed using Data Definition Language SQL statements.
• The most important Data Definition Language statements are
– CREATE create database, table with columns
– ALTER modifies the table and column structure
– DROP removes the tables and columns from the database
1-87
Data Definition Language (DDL),…
• The SQL data-definition language (DDL) allows the specification of
information about relations, including:
– The schema for each relation.
1-88
How to create and use databases
• To Display the existing databases
– SHOW DATABASES; the SQL statement will return all the
existing databases in our database management software.
1-90
What is Database Table? (Contd.)
• A database table has a specified number of
columns, but it can have any number of rows.
• A single database must have a unique table
name, while, in multiple databases, same table
name can exist in other databases.
1-91
SQL Statement create Database
Table
• SQL statement to Select the database is
– USE existing-database-name;
• SQL statement to Display existing tables inside the selected
database is
– SHOW TABLES; returns all the existing tables inside the
selected database
• SQL statement to get the Structure of a database table is
– DESCRIBE table-name;
• SQL statement to delete a table is
– DROP TABLE existing-table-name;
1-92
SQL Statement to create new table
• The SQL statement to create a new database table is
CREATE TABLE table-name
(A1 D1, A2 D2, ..., An Dn,
(integrity-constraint1),
...,
(integrity-constraint n ));
– table-name is the name of the relation
– each Ai is an attribute name in the schema of relation table-name
– Di is the data type of values in the domain of attribute Ai
• Here is an example SQL statement to create a new table:
CREATE TABLE instructor (
ID CHAR(5) NOT NULL PRIMARY KEY,
name VARCHAR(20),
dept_name VARCHAR(20),
salary NUMERIC(8,2));
• This SQL statement creates a new table called instructor with the given
columns and their data types.
Integrity Constraints in Create Table
1-97
DROP (Contd.)
• DROP is used to remove a database and table
from the schema.
• Syntax is:
– DROP DATABASE existing database-name;
– DROP TABLE existing-table-name;
– Example: DROP DATABASE school; where school is
existing database name
• DROP TABLE user; where user is table name
1-98
ALTER
• The ALTER TABLE SQL statement is used to
– Rename (or) change table name,
– Add a column, change datatype of column, change the name of an
existing column and drop table columns in the existing database table
• To rename the table:
– ALTER TABLE old-table-name RENAME TO new-table-name;
• To add new column in the existing table name:
– ALTER TABLE table-name ADD new-column-name data type;
• To modify the column data type in the existing table:
– ALTER TABLE table-name MODIFY COLUMN column-name new data
type;
1-99
ALTER (Contd.)
• To drop a column from existing table
– ALTER TABLE table-name DROP COLUMN column-name;
• To change the name of an existing column name
– ALTER TABE table-name CHANGE old_column_name new-column-
name data type;
• Example: assume table name is user
– ALTER TABLE user RENAME TO user1;
– ALTER TABLE user ADD firstname VARCHAR(30);
– ALTER TABLE user MODIFY firstname VARCHAR(50);
– ALTER TABLE user CHANGE password pasd CHAR(20);
– ALTER TABLE user DROP firstname;
1-100
Data Manipulation Language
(DML)
• Data Manipulation Language is used to
express database queries and update
• DML is used to manage the data that resides
in our tables and columns
• DML changes only the data, not the database
structure
• The data inside a table is inserted, updated, or
deleted using the DML SQL statements
1-101
Data Manipulation Language
(DML)
• The most important Data Manipulation Languages are:
• INSERT INTO
• UPDATE
• DELETE
– INSERT SQL statement add the data
– UPDATE modifies the data
– DELETE removes the data from the database
• Language for accessing and updating the data organized by the
appropriate data model
– DML also known as query language
1-102
Data Manipulation Language
(DML),…
• There are basically two types of data-manipulation language
– Procedural DML -- require a user to specify what data are needed and
how to get those data.
– Declarative DML -- require a user to specify what data are needed
without specifying how to get those data.
• Declarative DMLs are usually easier to learn and use than are
procedural DMLs.
• Declarative DMLs are also referred to as non-procedural DMLs
• The portion of a DML that involves information retrieval is called
a query language.
1-103
INSERT INTO Statement
• The INSERT INTO statement is used to insert or add new data
rows (or) records to a database table
• To add data rows to a table, first select the existing database
1-104
INSERT INTO Statement (Contd.)
• Method 2:
1-105
INSERT INTO Statement (Contd.)
• The string values must be enclosed in double quotes, but
enclosed numeric values in quote is optional or not
required. Here arefew examples
• INSERT INTO teachers VALUES (“John Doe”, 1234);
• INSERT INTO students (firstname, lastname, class, age) VALUES
(“John”,”Doe”,”First”, 26);
• insert into instructor values (“10211”, “Smith”, “Biology”, 66000);
1-106
INSERT INTO Statement (Contd.)
• In first method, we must provide all columns values in
the sequence, while in the second method, we can add
the values to a selected columns
• In most of the cases, the second method is more
convenient.
1-107
UPDATE Statement
• UPDATE statement is used to update the data rows in a
database table
• The update statement can update one (or) multiple
column values in a single SQL statement
• WHERE clause is used to specify the data row to be
updated, UPDATE statement without WHERE clause will
update all the data rows in a table
1-108
UPDATE Statement (Contd.)
• Any existing data rows or records in target table remain
unaffected
• Syntax for update statement is:
– UPDATE table_name SET column_name = new_value WHERE condition;
• Example
– UPDATE tablename SET column1=newvalue;
1-109
Basic SQL Query Structure
• A typical SQL query has the form:
– Ai represents an attribute
– Ri represents a relation
– P is a predicate logic (condtion).
• The result of an SQL query is a relation.
The select Clause
• The select clause lists the attributes desired in the result of a
query
– Main purpose is to retrieve the data from the database
and return it in a tabular structure
• Example: find the names of all instructors:
select name from instructor;
• It defines the columns that will be returned in the final tabular
result set.
• It is executed after the FROM clause and any optional WHERE,
GROUP BY and HAVING clauses if present.
1-111
The select Clause
• The general SELECT statement syntax is:
SELECT expression(s) involving keywords, identifiers and constants
FROM table name
[WHER clause]
[GROUP BY clause]
[HAVING clause]
[ORDER BY clause]
1-112
The select Clause (Cont.)
• An asterisk in the select clause denotes “all attributes”
select *
from instructor
• An attribute can be a literal with from clause
select 'A'
from instructor
– Result is a table with one column and N rows
(number of tuples in the instructors table), each row
with value “A”
The select Clause (Cont.)
1-115
The select Clause (Cont.)
• SQL allows duplicates in relations as well as in query results.
• To force the elimination of duplicates, insert the keyword distinct
after select.
• Find the department names of all instructors, and remove
duplicates
select distinct dept_name
from instructor
• The keyword all specifies that duplicates should not be removed.
1-120
DELETE Statement
• DELETE removes the definition of the relation as well as the data in
the given relation, delete only deletes the tuples but maintains the
table definition.
• DELETE statement is used to delete the data rows in a database table
• The DELETE statement can delete one or multiple data rows from a
database table.
1-121
DELETE Statement (Contd.)
• WHERE clause is used to specify the data row to be deleted,
DELETE statement without WHERE clause will delete all the
data rows in a table
• Examples
– DELETE FROM table-name; Remove all tuples from the table
1-122
SQL Data Types
• NUMERIC data types stores only numeric values. Numeric data types
are integers, floating point numbers and fixed-point numbers.
– The INT data type stores integers ranging from 2,147,483,648 to 2,147,483,647.
An optional "unsigned" can be denoted with the declaration, modifying the range
to be 0 to 4,294,967,295.
– A FLOAT represents small decimal numbers, used when a somewhat
more precise representation of a number is required.
– E.g. Rainfall FLOAT (4, 2);
1-126
SQL functions
• These functions operate on the multiset of
values of a column of a relation, and return a
value
AVG: average value
MIN: minimum value
MAX: maximum value
SUM: sum of values
COUNT: number of values
1-127
SQL functions Cont’d…
• AVG : This SQL function returns the average value of a column
that contains numeric values
• SUM: This SQL function returns the sum of a column that
contains numeric values.
• MIN: This SQL function returns the smallest, or minimum value
found in a column that contains numeric values
• MAX: This SQL function returns the largest, or maximum value
found in a column that contains numeric values.
• COUNT: This SQL function returns the number of rows in a
table, or the number of rows that match a search criteria.
1-128
Aggregate Functions – Group By
1-131
SQL Constraints (Contd.)
• Referential integrity: ensures that rows cannot be deleted, which are
used by other records
• User-Defined Integrity: enforces some specific business rules that do not
fall into entity, domain, or referential integrity categories.
• The SQL constraints defines the specific rules to be follow to the column
data in a database table.
• While INSERTING, UPDATING or DELETING the data rows, if the constraints
rules are not followed, the system will display an error message and the
action will be terminated.
• The SQL constraints are defined while creating a new database table. We
can also alter the table and add new constraints. The standard SQL supports
six constraints: NOT NULL, UNIQUE, PRIMARY KEY, FORIGEN KEY, CHECK
and DEFAULT.
1-132
PRIMARY KEY Constraint
• The primary key constraint is useful to restrict
storing of duplicate data rows in a given
column.
• The primary key column cannot contain NULL
values.
• The primary key can be defined while creating
a new database table or can be added by
using ALTER statement.
1-133
HAVING Clause
• It is designed for use with the GROUP BY
clause to restrict the groups that appear in the
final result table.
• WHERE clause filters individual rows going
into the final result table
• HAVING clause filters groups going into the
final result table.
1-134
What is SQL Injection?
• SQL Injection refers to the act of someone inserting a MySQL
statement to be run on your database without your
knowledge.
• SQL injection is a method where a malicious user can inject
some SQL commands to display other information or destroy
the database, using form fields on web page or application.
• Injection usually occurs when you ask a user for input, like their
name, email and instead of that, they give you a MYSQL
statement that you will unknowingly run on your database.
1-135
What is SQL Injection? (Contd.)
• SQL injection is a code injection technique that might destroy
your database
• SQL injection is one of the most common web hacking
techniques,
• by using SQL injection, a hacker may get access to other users
password and other information
• SQL injection is the placement of malicious code in SQL
statements, via web page input
1-136
Fundamentals of Database
Systems
1-137