Week 2 Complete
Week 2 Complete
Applications
Device Driver
Storage Media
(Hard Disk, Flash Memory)
Why do we need a DBMS?
24
3. Integrity problems
E.g., consider a bank application
The balance cannot be below10000 PKR
The day of a month cannot exceed 31
4. Atomicity of updates
E.g., consider a bank application
We want to transfer 1000 from account A to
account B
Steps:
Step 1: We deduct 1000 from account A
Step 2: Then, we increment 1000 in account B
If the system crashes at Step 1, then Step 2 cannot
be executed
Read 5000
Read 5000
5000 - 1000
DBMS makes sure that the
5000 - 1000 concurrent
Write 4000 access cannot lead to this problem
Write 4000
Drawback of File System
31
6. Security Problems
E.g., consider a bank application
We do not want system programmers to have
permissions to read some data
(e.g., Customer A’s saving account and
Customer B’s saving account)
Need a lot of effort to re-write a program for
this permission system
New customer
Order Picking
Order Slip
Customer Invoice Orde Warehouse
System r
Ship
Stateme
nt
New 1
info D Customer
New customer 1 Master
Add
Customer
Packing
slip Warehouse
3
Warehouse
2
Picking
Cust Info Order
Order Process Slip
Customer Produced
Customer Pending Picked
Order Order
Backorder
Proc 4
Info
D Back D Inventory Ship
3 Order 2 Master Shipping statement Customer
Ship N/A Prepare
among them.
id Customer-street
Customer-city
Customer-name
Loan-number amount
192-83-7465 Johnson
Alma Palo Alto A-101
019-28-3746 Smith
North Rye A-215
192-83-7465 Johnson
Alma Palo Alto A-201
321-12-3123 Jones
Main Harrison A-217
019-28-3746 Smith
North Rye A-201
49
Relation Model
50
51
Database
Database Systems
Systems provide
provide users
users with
with an
an abstract
abstract
view
view of
of data
data hiding
hiding certain
certain details
details of
of how
how data
data are
are
stored
stored and
and maintained
maintained
53
Data Abstraction
Physical Level
Describes how data is actually stored
Logical Level
Describes what data are stored in the database and what
relationships exist among those data
View Level
Describes only part of the entire database hiding details of
data types.
Views can also hide information (e.g., salary) for security
purposes
54
Level of Abstraction
Company database
Files on disks
Instances and Schemas
Similar to variable declarations and variable values in programming
languages
At instance t1
Student
Students;s;
struct
structstudent
student{{ s.name=
s.name=Florence;
Florence;
string
stringname;
name; s.age=25;
s.age=25;
int
intage;
age; s.gap=3.5;
s.gap=3.5;
float
floatgpa;
gpa;
};
}; Instances
At instance t2
s.name=
s.name=Jonathan;
Jonathan;
s.age=21;
s.age=21;
Schema s.gap=3.2;
s.gap=3.2;
56
Data Abstraction
57
Conceptual Schema
The conceptual schema (sometimes called the
logical schema) describes the stored data in terms of
the data model of the DBMS.
In a relational DBMS, the conceptual schema
describes all relations that are stored in the database.
Data Abstraction (using schemas)
58
Conceptual Schema
University Database
Students(sid: string, name: string, login: string, age: integer, gpa:
real)
Faculty(fid: string, fname: string, sal: real)
Courses(cid: string, cname: string, credits: integer)
Rooms(rno: integer, address: string, capacity: integer)
Enrolled
Teaches
Meets In
Data Abstraction
59
Physical Schema
The physical schema specifies additional storage
details.
It summarizes how the relations described in the
conceptual schema are actually stored on secondary
storage devices such as disks.
Decides file organizations to store the relations.
Creates Indexes to speed up data retrieval.
Decisions depend upon an understanding the data is
typically accessed.
Data Abstraction
60
Physical Schema
Indexes on University Database
E.g. File formats, locations etc
Data Abstraction
61
External Schema
Allow data access to be customized (and authorized) at
the level of individual users or groups of users.
Any given database has exactly one conceptual schema
and one physical schema because it has just one set of
stored relations, but it may have several external
schemas, each tailored to a particular group of users.
Each external schema consists of a collection of one or
more views and relations from the conceptual schema.
Data Abstraction
62
External Schema
Find out the name of faculty member, room# and timings of
DBMS course.
Instance
The actual content of the database at a particular point in
time
Analogous to the value of a variable
63
Data Independence
Ability to modify a schema definition in one level without affecting a
schema definition in the next higher level.
The interfaces between the various levels and components should be well
defined so that changes in some parts do not seriously influence others.
64
Data Independence
Can
CanI Imake
makechanges
changeshere
herewithout
without Logical Logical
LogicalData
Data
affecting the application programs
affecting the application programs level Independence
Independence
Can
CanI Imake
makechanges
changeshereherewithout Physical Physical
without PhysicalData
Data
affecting the logical level
affecting the logical level level Independence
Independence
65
Physical Data Independence
The ability to modify the physical schema without
changing the logical schema
The logical schema is independent of the changes in
how the data is stored on disks, file structures etc.
Faculty: Faculty Name, Faculty ID, Faculty Office
66
Logical Data Independence
Application programs are insulated from changes in
the structure/design of the database
Faculty: Faculty Name, Faculty ID, Faculty Office
Give me the office number
of Nicolas Lomenie
We changed the schema to:
Office # 247
67
Structure of a DBMS
68
69
Application Programmers
Embed DML calls in program written in a host language (e.g., Cobol,
Java). (DML stands for data manipulation language)
e.g., programs that generates payroll checks, transfer funds between
accounts
Sophisticated users
Post request in database query language (SQL interface)
Naïve users
Invokes one of the permanent application programs that have been
written previously (web forms, application front ends)
e.g. transfer – transfer fund between accounts
Application Architecture
73