Sei sulla pagina 1di 50

Introduction to Database Management System

CSC 220

Dr. Ghulam Mustafa

Department of Computer Science and IT


Bahria University Lahore Campus

February 13, 2019


Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 1 / 50
Instructor Name, Cluster Head, Subject Expert

Instructor Name: Dr. Ghulam Mustafa


Cluster Head Name: Prof. Tahir Iqbal
Subject Expert Name: Prof. Asghar Ali Shah
HOD Computer Science Prof. Farhan Saeed Sherazi
Instructor Department: Dept. of Computer Sciences, Bahria
University, Lahore Campus, Pakistan
Instructor Email: gmustafa.bulc@bahria.edu.pk
Instructor Office Number: Tel (Off): +92-42-99233408-15 Ext: 257
Instructor Cell Number and Whatsapp : +44 7412534684
Web: https://www.bahria.edu.pk/bulc/
Instructor Contact Hours: Will be provided in class.

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 2 / 50


Course Objectives

Students successfully completing this course should be able:


1. To understand the different issues involved in the design and
implementation of a database system.
2. To study the physical and logical database designs, database
modeling, relational, hierarchical, and network models.
3. To understand and use data manipulation language to query,
update, and manage a database.
4. To develop an understanding of essential DBMS concepts such as:
database security, integrity, and concurrency.
5. To familiarize with the concepts of distributed database, and
intelligent database, Client/Server (Database Server), data
warehousing and data mining.
To design and build a simple database system and demonstrate
competence with the fundamental tasks involved with modeling,
designing, and implementing a DBMS.
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 3 / 50
Reference Books

Database System Concepts, 6th Edition by Avi Silbechatz, Henry F.


Korth and S. Sudarshan.
Database Systems: A Practical Approach to Design, Implementation,
and Management, 6th Edition by Thomas Connolly and Carolyn Begg
Database Systems: The Complete Book, 2nd Edition by Hector
Garcia-Molina, Jeffrey D. Ullman, Jennifer Widom
Database Management Systems, 3rd Edition by Raghu Ramakrishnan,
Johannes Gehrke

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 4 / 50


Outlines
DBMS

Figure 1: Database System (HEC Roadmap)


Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 5 / 50
Course Contents

Basic database concepts, Database approach vs file based system,


database architecture, three level schema architecture, data
independence, relational data model, attributes, schemas, tuples,
domains, relation instances, keys of relations, integrity constraints,
relational algebra, selection, projection, Cartesian product, types of
joins, normalization, functional dependencies, normal forms, entity
relationship model, entity sets, attributes, relationship,
entity-relationship diagrams, Structured Query Language (SQL), Joins
and sub-queries in SQL, Grouping and aggregation in SQL,
concurrency control, database backup and recovery, indexes, NoSQL
systems.

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 6 / 50


Teaching and Assesment

Teaching Methodology: Lectures, Written Assignments, Practical labs,


Semester Project, Presentations
Course Assessment: Sessional Exam, Home Assignments, Quizzes,
Project, Presentations, Final Exam

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 7 / 50


Week-1 Course Outlines

Introduction to DBMS and its sublanguages:


The Need for Databases
Data Models
Relational Databases

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 8 / 50


Semester Calendar for Assignments/Quizzes/Project

Calender

Figure 2: Database System (Assignments Roadmap)

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 9 / 50


Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 10 / 50
Introduction Database Management System

Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 11 / 50
Introduction Database Management System

Database Management System

A database-management system (DBMS) is:


collection of interrelated data
Set of programs to access the data
The collection of data, usually referred to as the database, contains
information relevant to an enterprise.
DBMS provides an environment that is both convenient and efficient
to use.
Database Applications:
Banking: all transactions
Airlines: reservations, schedules
Universities: registration, grades
Sales: customers, products, purchases
Human resources: employee records, salaries, tax deductions
Databases touch all aspects of our lives
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 12 / 50
Introduction Database Management System

Database Example: University Database

What are the basic functions of a database?

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 13 / 50


Introduction Database Management System

Database Example: University Database

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
Initially, database applications were built directly on top of file systems

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 14 / 50


Introduction Database Management System

Database Example: Question

How about searching the records?

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 15 / 50


Introduction Database Management System

From Search to Recommender System

The Web is leaving the era of search and entering one of discovery.
What’s the difference?

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 16 / 50


Introduction Database Management System

From Search to Recommender System

Search is what you do when you’re looking for something. Discovery is


when something wonderful that you didn’t know existed, or didn’t
know how to ask for, finds you [?].

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 17 / 50


Introduction Drawbacks of using file systems to store data

Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 18 / 50
Introduction Drawbacks of using file systems to store data

Drawbacks of using file systems to store data

Data redundancy and inconsistency


Multiple file formats, duplication of information in different files
Difficulty in accessing data
Need to write a new program to carry out each new task
Data isolation
Multiple files and formats
Integrity problems
Integrity constraints (e.g., account balance > 0) become “buried” in
program code rather than being stated explicitly
Hard to add new constraints or change existing ones

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 19 / 50


Introduction Drawbacks of using file systems to store data

Drawbacks of using file systems to store data

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
Security problems
Hard to provide user access to some, but not all, data

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 20 / 50


Introduction Drawbacks of using file systems to store data

Database as solution

Database systems offer solutions to all the above problems


Recap: What is DBMS?

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 21 / 50


Introduction Levels of Abstraction

Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 22 / 50
Introduction Levels of Abstraction

Three Levels

Physical level:
describes how a record (e.g., instructor) is stored.
Logical level:
describes data stored in database, and the relationships among the
data.

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

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 23 / 50


Introduction Levels of Abstraction

View of Data

An architecture for a database system

Figure 3: Architecture of Database

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 24 / 50


Introduction Instances and Schemas

Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 25 / 50
Introduction Instances and Schemas

Instances and Schemas

The collection of information stored in the database at a particular


moment is called an instance of the database.
The overall design of the database is called the database schema.
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: the overall physical structure of the database
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

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 26 / 50


Data Models Data Model

Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 27 / 50
Data Models Data Model

Data Model

A collection of tools for describing


Data
Data relationships
Data semantics
Data constraints
A data model provides a way to describe the design of a database at
the physical, logical, and view levels.
Relational model: a collection of tables to repre- sent both data and
the relationships among those data
Entity-Relationship data model (mainly for database design): he
entity-relationship (E-R) data model uses a collection of basic objects,
called entities, and relationships among these objects.
An entity is a “thing” or “object” in the real world that is
distinguishable from other objects.

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 28 / 50


Data Models Data Model

Data Model(cont,)

Object-based data models (Object-oriented and Object-relational): the


development of an object-oriented data model can be seen as
extending the E-R model with notions of encapsulation, methods
(functions), and object identit
Semistructured data model (XML): The semistructured data model
permits the specification of data where individual data items of the
same type may have different sets of attributes.
Other older models:
Network model
Hierarchical model

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 29 / 50


Database System Languages Data Manipulation Language (DML)

Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 30 / 50
Database System Languages Data Manipulation Language (DML)

1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 31 / 50


Database System Languages Data Manipulation Language (DML)

Data Manipulation Language (DML)

A database system provides a data-definition language to specify the


database schema and a data-manipulation language to express
database queries and updates
Language for accessing and manipulating the data organized by the
appropriate data model
DML also known as query language
Retrievalofinformationstoredinthedatabase
Insertionofnewinformationintothedatabase
Deletionofinformationfromthedatabase
Modificationofinformationstoredinthedatabase
SQL is the most widely used query language

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 32 / 50


Database System Languages Data Manipulation Language (DML)

Data Manipulation Language (DML), Cont

Two classes of languages


Procedural – user specifies what data is required and how to get those
data
Declarative (nonprocedural) – user specifies what data is required
without specifying how to get those data
The database system has to figure out an efficient means of accessing
data in Declarative.
SQL is the most widely used query language
A query is a statement requesting the retrieval of information. The
portion of a DML that involves information retrieval is called a query
language.

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 33 / 50


Database System Languages Data Definition Language (DDL)

Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 34 / 50
Database System Languages Data Definition Language (DDL)

1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 35 / 50


Database System Languages Data Definition Language (DDL)

Data Definition Language (DDL)

a database schema by a set of definitions expressed by a special


language called a data-definition language (DDL).
Specification notation for defining the database schema

Figure 4: Example

DDL compiler generates a set of tables stored in a data dictionary


Data dictionary contains metadata (i.e., data about data)

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 36 / 50


Database System Languages Data Definition Language (DDL)

Data Definition Language (DDL), cont

For example, suppose the university requires that the account balance
of a department must never be negative.
How it will be ensured ?

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 37 / 50


Relational Database

Relational Database

What is a relational database?

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 38 / 50


Relational Database

Relational Database

A relational database is based on the relational model and uses a


collection of tables to represent both data and the relationships among
those data.
It also includes a DML and DDL.

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 39 / 50


Relational Database Relational Model

Outline
1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary
Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 40 / 50
Relational Database Relational Model

Relational Model

Example of tabular data in the relational model

Figure 5: Example of RM

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 41 / 50


Relational Database Relational Model

A Sample Relational Database

Figure 6: Example of Relational Database


Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 42 / 50
SQL

1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 43 / 50


SQL

SQL

SQL: widely used non-procedural language

Figure 7: Example1

Figure 8: Example2

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 44 / 50


SQL

Relational Model

Example of tabular data in the relational model


What is DML and DDL and DML?

Figure 9: Example of RM

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 45 / 50


SQL

Database Design

The process of designing the general structure of the database:


Logical Design – Deciding on the database schema. Database design
requires that we find a “good” collection of relation schemas.
Physical Design – Deciding on the physical layout of the database

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 46 / 50


SQL

The Entity-Relationship Model

Models an enterprise as a collection of entities and relationships


Entity: a “thing” or “object” in the enterprise that is distinguishable
from other objects
Relationship: an association among several entities
Represented diagrammatically by an entity-relationship diagram:

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 47 / 50


SQL

The Entity-Relationship Model

ERM

Figure 10: ERM

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 48 / 50


Summary

1 Introduction
Database Management System
Drawbacks of using file systems to store data
Levels of Abstraction
Instances and Schemas
2 Data Models
Data Model
3 Database System Languages
Data Manipulation Language (DML)
Data Definition Language (DDL)
4 Relational Database
Relational Model
5 SQL
6 Summary

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 49 / 50


Summary

Summary

Many applications of databases


DBMS are key application to deal with old file system

Dr. Ghulam Mustafa (BULC) Week1 February 13, 2019 50 / 50

Potrebbero piacerti anche