You are on page 1of 42

1

CS311 Introduction to
Database systems
“YOU CAN HAVE DATA WITHOUT
INFORMATION, BUT YOU CANNOT HAVE
INFORMATION WITHOUT DATA.”

Course Instructor: Engr. Ruqqiya Asad


2

Books
Database Management Systems, 3rd Edition - Raghu Ramakrishnan.

Introduction to Database Systems, Seventh Edition - C. J. Date.

SQL, PL/SQL: The Programming Language Of Oracle 4th Edition - Ivan Bayross.
3

Memory
HUMAN

WHY?
Do you remember everything of your life?
We don't have to go that far:
Every single time we go out for the shopping :)
Do we remember the items we purchased in last Year?
Think:
Its about quantity of information? Or quality of information? Or Both?
Why it is essential to memorize everything?
4

Storage
WHY?
Maintains.
Students notes.
Patients information.
NADRA
Passport
Tax
What would be the best option to mark attendance, if instructor don't have any
automated attendance sheet.
Slide 1-
Basic Definitions 6

 Database:
 A collection of related data.
 Data:
 Known facts that can be recorded and have an implicit meaning.
 Mini-world:
 Some part of the real world about which data is stored in a database. For
example, student grades and transcripts at a university.
 Database Management System (DBMS):
 A software package/system to facilitate the creation and maintenance of a
computerized database.

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Drawbacks of using file systems to store data 7
More Memory usage in file system
Required attributes to search the data in file system
Data redundancy and inconsistency
Multiple file formats, duplication of information in different files
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
 Example: Two people reading a balance (say 100) and updating it by withdrawing money (say 50 each) at the same time
Securityproblems
 Hard to provide user access to some, but not all, data

Database systems offer solutions to all the above problems


Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan
Database Management System (DBMS)
8
 DBMS contains information about a particular enterprise
 Collection of interrelated data
 Set of programs to access the data
 An environment that is both convenient and efficient to use
 Database Applications:
 Banking: transactions
 Airlines: reservations, schedules
 Universities: registration, grades
 Sales: customers, products, purchases
 Online retailers: order tracking, customized recommendations
 Manufacturing: production, inventory, orders, supply chain
 Human resources: employee records, salaries, tax deductions
 Databases can be very large.
 Databases touch all aspects of our lives
Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan
University Database Example 9

 Application program examples


 Add new students, instructors, and courses
 Register students for courses, and generate class rosters
 Assign grades to students, compute grade point averages (GPA) and generate transcripts
 In the early days, database applications were built directly on top of file systems

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


What a DBMS Facilitates 10

 Define a particular database in terms of its data types, structures, and


constraints
 Construct or load the initial database contents on a secondary storage
medium
 Manipulating the database:
 Retrieval: Querying, generating reports
 Modification: Insertions, deletions and updates to its content
 Accessing the database through Web applications
 Processing and sharing by a set of concurrent users and application
programs – yet, keeping all data valid and consistent

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Other DBMS Functionalities Slide 1-
11

 DBMS may additionally provide:


 Protection or Security measures to prevent unauthorized access
 “Active” processing to take internal actions on data
 Presentation and visualization of data
 Maintenance of the database and associated programs over the lifetime of the database
application

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Levels of Abstraction 12
 Physical level: describes how a record (e.g., instructor) is stored.
 Logical level: describes data stored in database, and the relationships
among the data.
type instructor = record
ID : string;
name : string;
dept_name : string;
salary : integer;
end;

 View level: application programs hide details of data types. Views can
also hide information (such as an employee’s salary) for security
purposes.

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


View of Data 13
An architecture for a database system

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Instances and Schemas 14
 Similar to types and variables in programming languages
 Logical Schema – the overall logical structure of the database
 Example: The database consists of information about a set of customers and accounts in a bank
and the relationship between them
 Physical schema– defines how the data is stored and managed on the physical hard disk of
the devices the database is running on.
 Instance – the actual content of the database at a particular point in time
 Physical Data Independence – the ability to modify the physical schema without changing
the logical schema
 Applications depend on the logical schema
 In general, the interfaces between the various levels and components should be well defined so
that changes in some parts do not seriously influence others.

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Data Models 15
 Data models define how the logical structure of a database is modeled. 
 A collection of tools for describing
 Data
 Data relationships
 Data semantics
 Data constraints
 Relational model
 Entity-Relationship data model (mainly for database design)
 Object-based data models (Object-oriented and Object-relational)
 Semistructured data model (XML)
 Other older models:
 Network model
 Hierarchical model

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Relational Model 16
 All the data is stored in various tables. Columns
 Example of tabular data in the relational model

Rows

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


A Sample Relational Database 17

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Data Definition Language (DDL) 18
 Specification notation for defining the database schema
Example: create table instructor (
ID char(5),
name varchar(20),
dept_name varchar(20),
salary numeric(8,2))
 DDL compiler generates a set of table templates stored in a data dictionary
 Data dictionary contains metadata (i.e., data about data)
 Database schema
 Integrity constraints
 Primary key (ID uniquely identifies instructors)
 Authorization
 Who can access what

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Data Manipulation Language (DML) 19

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
 Language for accessing and manipulating the data organized by the appropriate data model
 DML also known as query language
 Here are some different DML commands:
 INSERT INTO Command
 This command can be used to insert data into a row of a table. I
 UPDATE Command
 This statement in SQL is used to update the data that is present in an existing table of a database. The UPDATE statement can
be used to update single or multiple columns on the basis of our specific needs.
 DELETE Command
 The DELETE statement can be used in SQL to delete various records from a given table. On the basis of the condition that has
been set in the WHERE clause, one can delete single or multiple records.
SQL (Structured Query Language) 20
 The most widely used commercial language

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
 SQL is NOT a Turing machine equivalent language
 SQL is a programming language for Relational Databases.
 It is designed over relational algebra and tuple relational calculus. SQL comes
as a package with all major distributions of RDBMS.
 SQL comprises both data definition and data manipulation languages. Using the
data definition properties of SQL, one can design and modify database schema,
whereas data manipulation properties allows SQL to store and retrieve data
from database.
Database Design 21
The process of designing the general structure of the database:

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
 Logical Design – Deciding on the database schema.
Database design requires that we find a “good” collection of
relation schemas.
 Business decision – What attributes should we record in the
database?
 Computer Science decision – What relation schemas should
we have and how should the attributes be distributed among
the various relation schemas?
 Physical Design – Deciding on the physical layout of the
database
Database Design (Cont.) 22
 Is there any problem with this relation?

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
Design Approaches 23
 Need to come up with a methodology to ensure that each of the relations

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
in the database is “good”
 Two ways of doing so:
 Entity Relationship Model (Chapter 7)
 Models an enterprise as a collection of entities and relationships
 Represented diagrammatically by an entity-relationship diagram:
 Normalization Theory (Chapter 8)
 Formalize what designs are bad, and test for them
24
BASIC TERMONOLOGIES RELATED TO DATABASE AND SQL

Relation: In general, a relation is a table, i.e., data is arranged in rows and columns. 
Tuple: The rows of tables in a relationship are generally termed Tuples.
Attributes: The columns or fields of a table are termed Attributes.
Degree: The number of attributes in a relation determines the degree of the relation. A
relation having three attributes is said to have a relation of degree 3.
Cardinality: The number of tuples or rows in a relation is termed cardinality.
Main Characteristics of the Database Slide 1-

Approach
25

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
 Self-describing nature of a database system:
 A DBMS catalog stores the description of a particular database (e.g. data
structures, types, and constraints)
 The description is called meta-data*.
 This allows the DBMS software to work with different database
applications.
 Insulation between programs and data:
 Called program-data independence.
 Allows changing data structures and storage organization without having
to change the DBMS access programs.
Database Concepts 6th Edition @ Silberschatz, korth &
Slide 1-

Sudarshan
26
Example of a Simplified Database Catalog
Main Characteristics of the Database Slide 1-
27

Approach (continued)

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
 Data Abstraction:
 A data model is used to hide storage details and present the users with a
conceptual view of the database.
 Programs refer to the data model constructs rather than data storage details
 Support of multiple views of the data:
 Each user may see a different view of the database, which describes only the
data of interest to that user.
Main Characteristics of the Database Slide 1-
28

Approach (continued)

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
 Sharing of data and multi-user transaction processing:
 Allowing a set of concurrent users to retrieve from and to update the
database.
 Concurrency control within the DBMS guarantees that each
transaction is correctly executed or aborted
 Recovery subsystem ensures each completed transaction has its effect
permanently recorded in the database
 OLTP (Online Transaction Processing) is a major part of database
applications. This allows hundreds of concurrent transactions to
execute per second.
Database Users Slide 1-
29

Sudarshan
Database Concepts 6th Edition @ Silberschatz, korth &
 Users may be divided into
 Those who actually use and control the database content, and those who design,
develop and maintain database applications (called “Actors on the Scene”), and
 Those who design and develop the DBMS software and related tools, and the computer
systems operators (called “Workers Behind the Scene”).
Database Concepts 6th Edition @ Silberschatz, korth &
Slide 1-

Sudarshan
30
Database Users – Actors on the
Scene
Database Concepts 6th Edition @ Silberschatz, korth &
31

Sudarshan
Database Users – Actors on the Scene
Database Concepts 6th Edition @ Silberschatz, korth &
32

Sudarshan
Database Users – Actors on the Scene
Database Concepts 6th Edition @ Silberschatz, korth &
33

Sudarshan
Database Users – Actors on the Scene
Database Concepts 6th Edition @ Silberschatz, korth &
Slide 1-

Sudarshan
34
Database Users – Actors on the Scene
Database Users – Actors behind the Scene 35

System Designers and Implementers: Design and implement DBMS


packages in the form of modules and interfaces and test and debug them. The
DBMS must interface with applications, language compilers, operating
system components, etc.
Tool Developers: Design and implement software systems called tools for
modeling and designing databases, performance monitoring, prototyping, test
data generation, user interface creation, simulation etc. that facilitate building
of applications and allow using database effectively.
Operators and Maintenance Personnel: They manage the actual running
and maintenance of the database system hardware and software environment.

Database Concepts 6th Edition @ Silberschatz, korth & Sudarshan


Basic data retrieval operations 36
Basic data retrieval operations 37
Basic data retrieval operations 38
Basic data retrieval operations 39
Basic data retrieval operations 40
Basic data retrieval operations 41
Basic data retrieval operations 42
Basic data retrieval operations 43

You might also like