0% found this document useful (0 votes)
8 views133 pages

DBMS Unit-II-The Relational Model

The document provides information about a lecture on database management systems. It outlines the topics, objectives, expected outcomes, references and more that will be covered in the lecture.

Uploaded by

anonymous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views133 pages

DBMS Unit-II-The Relational Model

The document provides information about a lecture on database management systems. It outlines the topics, objectives, expected outcomes, references and more that will be covered in the lecture.

Uploaded by

anonymous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 133

Lecture By: Syed Nawaz Pasha

Assistant Professor
CS&AI
Class: CSE-II/II
 The Relational Model, Relational
Syllabus: database design using ER.
 ER to relational mapping
 Relational algebra and relational
calculus
 Tuple Relational Calculus, Domain
Relational Calculus, SQL.

Database Management Systems Syed Nawaz(Asst Professor)


 To know how the data will be stored.
 To know how to specify the constraints that
Objectives: need to be satisfied while storing the data.
 To know How to create Databases and Tables.
 To know How to insert the data into the tables
and how to delete the data.
 To know how to specify queries using Relational
Algebra and Relational Calculus.

Database Management Systems Syed Nawaz(Asst Professor)


 Students will be able to query the database for
finding out any information from database systems.
Expected  Students will able to create the databases, tables
Outcomes:  They can specify what type of constraints the data
needs to satisfy before it is going to store in database
 They can also modify the structure of the tables with
the help of alter command.
 Students can write queries using relational algebra
and relational calculus.

Database Management Systems Syed Nawaz(Asst Professor)


1. INTRODUCTION TO RELATIONAL MODEL
2. Relational Model Concepts
Topics: 3. Integrity Constraints over Relations
• Domain Constraints
• Key Constraints
• Entity Integrity
• Referential Integrity and Foreign Keys
4. ER-TO-RELATIONAL MAPPING
5. SQL Introduction
6. SQL Data Types
7. SQL Basics

Database Management Systems Syed Nawaz(Asst Professor)


8. Relational Algebra
 Unary Relational Operations:
Topics:  Relational Algebra Operations from Set Theory
 Binary Relational Operations: JOIN and DIVISION
9. Relational Calculus
 The Tuple Relational Calculus
 The Domain Relational Calculus

Database Management Systems Syed Nawaz(Asst Professor)


 Raghurama Krishnan, Johannes Gehrke“,
Data base Management Systems” TATA
McGrawHill 3rd Edition.
 Silberschatz, Korth “Data base System
Concepts” McGraw hill, V Edition.

Database Management Systems Syed Nawaz(Asst Professor)


 Open the word document and display…

Database Management Systems Syed Nawaz(Asst Professor)


 Let us learn the terms
 Data Vs Information
 Data Vs Database
 Database vs Database Management
System(DBMS)

Database Management Systems Syed Nawaz(Asst Professor)


 Data Vs Information
 Data - contain raw facts. It may be either
text, numbers ,images, audio , video, maps.
 Processing – Conversion of raw data into
useful information is known as Processing.
 Information - Processed Data is Known as
Information based on which knowledge can
be acquired

Database Management Systems Syed Nawaz(Asst Professor)


Database Management Systems Syed Nawaz(Asst Professor)
 Microsoft Access
 Mysql
 Oracle*
 Microsoft SQL server
 IBM DB2
 PostgreSQL

Database Management Systems Syed Nawaz(Asst Professor)


Good Afternoon?
Good Afternoon CSE?
Good Afternoon CSE II Year?
Good Afternoon CSE II-IIsem G-Section
students-yes clear meaningful information
targeted to only CSE(II/II) students of Setion-
G

Database Management Systems Syed Nawaz(Asst Professor)


 What is DBMS?
 A DBMS is a collection of interrelated data and a
set of programs to access those data.
 What is Database?
 It is a collection of related data.
 Example: University database which includes students,
faculty, courses & class rooms information along with
activities such as enrolment and teaching courses.

Database Management Systems Syed Nawaz(Asst Professor)


Database Management Systems Syed Nawaz(Asst Professor)
 Provide a way to store and retrieve database
information that is both convenient and
efficient.
 Why DBMS?
 Manage large amount of information
 Provide safety of information stored.
 Prevent unauthorized access.
 Consistency(when DB is shared)

Database Management Systems Syed Nawaz(Asst Professor)


 Banking – For customer information, accounts, and
loans, and banking transactions.
 Airlines – For reservation and schedule information,
flight details etc.
 Universities – For student and faculty information,
course registrations, and grades. [registration,
grades]

Database Management Systems Syed Nawaz(Asst Professor)


 Credit Card Transactions – For purchases on credit
card and generation of monthly statements.
 Telecommunication – For keeping records of calls
made, generating monthly bills, maintaining
balances on prepaid calling cards, and storing
information about communication networks.
 Finance – For storing information about holdings,
sales, and purchases of financial instruments such as
stocks and bonds.

Database Management Systems Syed Nawaz(Asst Professor)


 Sales – For customer, product, and purchase information.
[customers, products, purchases]
 Manufacturing – For management of supply chain and
for tracking production of items in factories, inventories
of items in warehouses/stores, and orders for items.
[production, inventory, orders, supply chain]

 Human Resources – For information about employees,


salaries, payroll taxes and benefits, and generation of
paychecks. [employee records, salaries, tax deductions]

Database Management Systems Syed Nawaz(Asst Professor)


 DBMS has become basic requirement of
every enterprize.
 User interfaces hide details of access to
database and most people are not even
aware of it.

Database Management Systems Syed Nawaz(Asst Professor)


 File System:
 Before the evolution of DBMS, File Systems are used to
store and manage the data.
 In File System data will be stored in individual files.
 A File is a collection of data.
 Files are typically designed to meet needs of a particular
department or user group.

Database Management Systems Syed Nawaz(Asst Professor)


 In the file processing approach, each department
would "own" a collection of relevant data and
software applications to manipulate that data.

Database Management Systems Syed Nawaz(Asst Professor)


1. Data Redundancy and Inconsistency
2. Difficulty in accessing data
3. Data isolation
4. Enforcing Integrity constraints
5. Atomicity problems
6. Difficulty in concurrency control
7. Security Problems

Database Management Systems Syed Nawaz(Asst Professor)


Data Redundancy and Inconsistency:
 Data redundancy means appearing same data in
different places.
 In file system same information is stored at different
File System
places it causes data-inconsistency problems during
updates.
Difficulty in accessing data:
 In file system application programs are used to
retrieve the data from the file.
 In order to retrieve data from files we need to write
special application program every time.
 This is not a convenient way because every time the
requirements may change need to write a new
program to carry out each new task
Database Management Systems Syed Nawaz(Asst Professor)
Data isolation
The data is scattered in different files and with different
formats in different locations.
To retrieve the data from the files separate programs are
required for each and every format and location.
File System So it is difficult to write application programs to retrieve
the data.
Enforcing Integrity constraints
Data integrity means, all the data has to obey some
condition.
Ex: Maximum marks of subject, Minimum balance of
account.
In file system it is difficult to set such type of constraints.
In File System integrity constraints are set at program
level.
Database Management Systems Syed Nawaz(Asst Professor)
Atomicity problems:
 Atomicity is a property of a transaction it states
that either all actions to be performed or none.
 In file processing system incomplete transactions
cannot be roll back.
 Due to this data will be inconsistent.
File System
Difficulty in concurrency control:
 concurrency means same file is accessed /updated
by different application programs at the same
time.
 In File Processing System it is not possible to
control concurrency.

Database Management Systems Syed Nawaz(Asst Professor)


Security Problems
 Since the information is scattered in different
files and does not have centralized access path,
so it is not possible to provide security to the
data so that everyone can access the data.
File System

Database Management Systems Syed Nawaz(Asst Professor)


1. Controlling Redundancy
2. Data Consistency
3. Data Security
4. Providing Storage Structures for Efficient Query
Processing
5. Providing Backup and Recovery
6. Providing concurrency control
7. Enforcing Integrity constraints
8. Report Writers

Database Management Systems Syed Nawaz(Asst Professor)


 In non-database systems (File system) same data is
stored in many places.
 Redundancy leads to several problems 1.duplication
effort: same data can be entered multiple times 2.
Storage space is wasted. 3. Data inconsistency.
 In DBMS, all the data is stored in one place.
 In DBMS, all the data of an organization is
integrated into a single database.
 By controlling the data redundancy, you can save
storage space

Database Management Systems Syed Nawaz(Asst Professor)


 By controlling the data redundancy, the data
consistency is obtained.
 If a data item appears only once, any update to its
value has to be performed only once and the
updated value (new value of item) is immediately
available to all users.
 If the DBMS has reduced redundancy to a minimum
level, the database system enforces consistency.

Database Management Systems Syed Nawaz(Asst Professor)


 It is the protection of the database from
unauthorized users.
 Only the authorized persons are allowed to access
the database.
 Some of the users may be allowed to access only a
part of database i.e., the data that is related to them
or related to their department.
 Mostly, the DBA can access all the data in the
database.

Database Management Systems Syed Nawaz(Asst Professor)


 Some users may be permitted only to retrieve data, whereas
others are allowed to retrieve as well as to update data.
 The database access is controlled by the DBA.
 DBA creates the accounts of users and gives rights to access
the database.
 Typically, users or group of users are given usernames
protected by passwords.
 Most of the DBMSs provide the security sub-system, which
the DBA uses to create accounts of users and to specify
account restrictions.

Database Management Systems Syed Nawaz(Asst Professor)


 Database systems must provide capabilities to
execute queries efficiently.
 Because the database is typically stored on disk, the DBMS
must provide specialized data structures to speed up disk
search for the desired records.
 Auxiliary files called indexes are used for this purpose.
 Indexes are typically based on tree data structures or hash
data structures.
 DBMS supports file manager to manage the allocation of
disk space for the DBMS files.
 Also it supports Buffer Manager to manage the memory
buffers used for processing the database information.

Database Management Systems Syed Nawaz(Asst Professor)


Most of the DBMSs have the 'backup and recovery'
sub-systems that automatically create the backup
of data and restore data if required.
 For example, if the computer system fails in the
middle of an update operation of the program, the
recovery sub-system is responsible for making sure
that the database is restored to the state it was in
before the program started executing.

Database Management Systems Syed Nawaz(Asst Professor)


 DBMS will support concurrency control tools for
permitting multiple users or application programs to
access the database concurrently, while preserving
the consistency of database.

Database Management Systems Syed Nawaz(Asst Professor)


 Integrity constraints can be applied to database so that
correct data can be entered in to database.
Ex: 1. minimum balance of a account is 1000
2. Max marks of a subject is 100
 Most database applications have certain integrity constraints
that must hold for the data.
 A DBMS should provide capabilities for defining and
enforcing these constraints.
 The simplest type of integrity constraint involves specifying
a data type for each data item.

Database Management Systems Syed Nawaz(Asst Professor)


 Most of the DBMSs provide the report writer tools
used to create reports.
 The users can create reports very easily and quickly.
 Once a report is created, it can be used many times
and it can be modified very easily

Database Management Systems Syed Nawaz(Asst Professor)


 A major purpose of the database system is to
provide users with an abstract view of the
data.
 Abstract ViewThe system hides certain
details of how the data are stored and
maintained.

Database Management Systems Syed Nawaz(Asst Professor)


 Developers hide the complexity from users
through several levels of abstraction to
simplify user’s interaction with the system.
 Three levels of Abstraction:
 Physical Level
 Logical Level
 View Level

Database Management Systems Syed Nawaz(Asst Professor)


Database Management Systems Syed Nawaz(Asst Professor)
 Data abstraction is a process of hiding the
implementation details (such as how the data are
stored and maintained) and representing only the
essential features to simplify user's interaction with
the system.
 To simplify user's interaction with the system, the
complexity is hidden from the database users
through several levels of abstraction.

Database Management Systems Syed Nawaz(Asst Professor)


 Highest level of abstraction.
 Describes only part of the database for a particular group of users.
 Can be many different views of a database.
 Example: If we have a login-id and password in a university system, then as a student, we
can view our marks, attendance, fee structure, etc. But the faculty of the university will
have a different view. He will have options like salary, edit marks of a student, enter
attendance of the students, etc. So, both the student and the faculty have a different view.
By doing so, the security of the system also increases. In this example, the student can't edit
his marks but the faculty who is authorized to edit the marks can edit the student's marks.
Similarly, the dean of the college or university will have some more authorization and
accordingly, he will have his view. So, different users will have a different view according to

the authorization they have .

Database Management Systems Syed Nawaz(Asst Professor)


 Next highest level of abstraction.
 Describes what data are stored and what relationships exit among
those data.
 Database administrator level.
 Example: Let us take an example where we use the relational model for storing the data. We
 have to store the data of a student, the columns in the student table will be student_name,
age,mail_id, roll_no etc. We have to define all these at this level while we are creating the
database. Though the data is stored in the database but the structure of the tables like the
student table, teacher table, books table, etc are defined here in the conceptual level or
logical level. Also, how the tables are related to each other is defined here. Overall, we can
say that we are creating a blueprint of the data at the conceptual level .

Database Management Systems Syed Nawaz(Asst Professor)


 Lowest level of abstraction.
 Describes how the data are stored.
 Complex low-level data structures described in detail.
 E.g: index, B-tree, hashing.
 It tells the actual location of the data that is being stored by the user. The
Database Administrators (DBA) decides that which data should be kept at which
particular disk drive, how the data has to be fragmented, where it has to be
stored etc. They decide if the data has to be centralized or distributed. Though
we see the data in the form of tables at view level the data here is actually stored
in the form of files only. It totally depends on the DBA, how he/she manages the
database at the physical level.

Database Management Systems Syed Nawaz(Asst Professor)


 Data model specifies how data is organized in database.
 A data model is a collection of concepts that can be used to
describe the structure of a database.
 Structure of a database mean the data types, relationships,
and constraints .
Types of Data Models
 Relational Model
 Entity-Relationship Model
 Object-Oriented Model
 Object-Relational Model
 Hierarchical Model
 Network Model

Database Management Systems Syed Nawaz(Asst Professor)


 Most commonly used model is the relational
model.
 In this model data is organized as two-
dimensional tables.
 The relational model uses a collection of tables
to represent both data and the relationships
among those data.
 Each table has multiple columns, and each
column has a unique name.
 Each table is called relation.
 Each row is called tuple.

Database Management Systems Syed Nawaz(Asst Professor)


Database Management Systems Syed Nawaz(Asst Professor)
 It is used to design database.
 Entity-Relationship model is based on the perception of a
real world that consists of a collection of basic objects called
“entities” and relationship among those objects..
 ER Model is based on:
 Entities and their attributes
 Relationships among entities

Database Management Systems Syed Nawaz(Asst Professor)


Entity
 An entity in ER Model is real world object, which has
some properties called attributes
 Attribute: descriptive properties of entity.
 It is a real world thing about which we want to
maintain a data.
 For example, in a school database, a student is
considered as an entity. Student has various
attributes like name, age and class etc.

Database Management Systems Syed Nawaz(Asst Professor)


 Relationship:
 It is an association among several entities.
Entity set: set of all entities of same type.
Relationship set: Set of all relationship of same
type.

Database Management Systems Syed Nawaz(Asst Professor)


Database Management Systems Syed Nawaz(Asst Professor)
 Database Schema refers to the overall structure of a database.
 The description of a database is called the database schema,

which is specified during database design and is not expected to


change frequently
Schema Diagram:
Schema
Student

Course

Teacher

Database Management Systems Syed Nawaz(Asst Professor)


 The information stored in the database at a particular
moment of time is called instance or database state.
 The distinction between database schema and database

state is very important.


Database state:
 At any point in time, the database has a current state.
instance

Database Management Systems Syed Nawaz(Asst Professor)


Three-Schema
architecture

3-Schema Architect
ure

Database Management Systems Syed Nawaz(Asst Professor)


 The internal schema uses a physical
data model that describes the
complete details of physical data
Three-Schema
architecture storage and access strategies.
 It tells us what data is stored in the
database and how.
 Physical Storage structures includes
B-trees, B+ tree and hash tables etc.
 Some of the access strategies are
primary index, single-level index and
multilevel index
Database Management Systems Syed Nawaz(Asst Professor)
 The conceptual level has a conceptual
schema, which describes the structure of
the whole database .
Three-Schema  The conceptual schema hides the details
architecture
of physical storage structures and
concentrates on describing entities, data
types, relationships, user operations, and
constraints.
 Usually, a representational data model is
used to describe the conceptual schema
when a database system is implemented.
Database Management Systems Syed Nawaz(Asst Professor)
 The external or view level includes a
number of user views.
 The external level is the view that
Three-Schema
architecture the individual user of the database
has.
 Each external schema describes the
part of the database that a particular
user group is interested in and hides
the rest of the database from that
user group.
Database Management Systems Syed Nawaz(Asst Professor)
 Data independence can be defined
as the capacity to change the
schema at one level of a database
Three-Schema
architecture system without having to change
the schema at the next higher level.
 We can define two types of data
independence:
1 Physical data independence
2. Logical data independence

Database Management Systems Syed Nawaz(Asst Professor)


 Physical data independence is the capacity to
change the internal schema without having to
change the conceptual schema.
Three-Schema  Hence, the external schemas need not be
architecture changed as well.
 Changes to the internal schema may be
needed because some physical files had to be
reorganized-for example, by creating
additional access structures-to improve the
performance of retrieval or update.

Database Management Systems Syed Nawaz(Asst Professor)


 Logical data independence is the
capacity to change the conceptual
schema without having to change
Three-Schema
architecture
external schema or application
programs.
 We may change the conceptual schema
to expand the database (by adding a
record type or data item), to change
constraints, or to reduce the database
(by removing a record type or data
item).
Database Management Systems Syed Nawaz(Asst Professor)
 SQL stands for “Structured Query Language”
and can be pronounced as “SQL” or “sequel –
(Structured English Query Language)”.
 It is a query language used for accessing and
SQL Introduction modifying information in the database.
 IBM first developed SQL in 1970s.
 Also it is an ANSI/ISO standard.
 It has become a Standard Universal Language
used by most of the relational database
management systems (RDBMS).

Database Management Systems Syed Nawaz(Asst Professor)


 Some of the RDBMS systems are: Oracle,
Microsoft SQL server, Sybase etc.
 Most of these have provided their own
implementation thus enhancing it's feature and
SQL Introduction making it a powerful tool.
 Few of the sql commands used in sql
programming are SELECT Statement, UPDATE
Statement, INSERT INTO Statement, DELETE
Statement, WHERE Clause, ORDER BY
Clause, GROUP BY Clause, ORDER Clause,
Joins, Views, GROUP Functions, Indexes etc.

Database Management Systems Syed Nawaz(Asst Professor)


• In a simple manner, SQL is a non-procedural,
English-like language that processes data in
groups of records rather than one record at a
SQL Introduction time. Few functions of SQL are:
1. store data
2. modify data
3. retrieve data
4. delete data
5. create tables and other database objects
6. modify tables and other database objects
7. describe tables and other database objects
8. Delete tables and other database objects

Database Management Systems Syed Nawaz(Asst Professor)


• SQL commands are instructions used to
communicate with the database to perform
specific task that work with data.
• SQL commands can be used not only for
SQL Introduction searching the database but also to perform
various other functions like, for example, you
can create tables, add data to tables, or modify
data, drop the table, set permissions for users.
etc.

Database Management Systems Syed Nawaz(Asst Professor)


SQL commands are grouped into four major categories
depending on their functionality
Data Definition Language (DDL):
These SQL commands are used for creating, modifying,
SQL Introduction and dropping the structure of database objects.
The commands are CREATE, ALTER, DROP,
DESCRIBE, and TRUNCATE.
Data Manipulation Language (DML):
These SQL commands are used for storing, retrieving,
modifying, and deleting data.
These commands are SELECT, INSERT,
UPDATE, and DELETE.

Database Management Systems Syed Nawaz(Asst Professor)


Transaction Control Language (TCL)
These SQL commands are used for managing
changes affecting the data.
These commands are COMMIT, ROLLBACK,
SQL Introduction and SAVEPOINT.
Data Control Language (DCL)
These SQL commands are used for providing
security to database objects.
These commands are GRANT and REVOKE.
Data Query Language(DQL)
These SQL commands are used query the
database
The only command is Select

Database Management Systems Syed Nawaz(Asst Professor)


Data Definition Language Statements (DDL) statements
are used to define the database structure or schema.
Different types of DDL commands are

1. Create
SQL Languages:
2. Drop
3. Alter
4. Truncate
5. Describe

Database Management Systems Syed Nawaz(Asst Professor)


Create command is used to create Databases,
Tables, and Views etc.
Syntax for Creating Databases:

Data Definition CREATE DATABASE DatabaseName;


Language
Statements: Example:
If you want to create new database, then CREATE
DATABASE statement would be as follows:

SQL> CREATE DATABASE university;

Database Management Systems Syed Nawaz(Asst Professor)


Syntax for Creating Table
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
Data Definition column3 datatype,
Language .....
Statements: columnN datatype,
PRIMARY KEY( one or more columns )
);

Database Management Systems Syed Nawaz(Asst Professor)


Drop command is used to drop the database or
table.
Syntax for Dropping the Database:

Data Definition
DROP DATABASE DatabaseName;
Language Example:
Statements: If you want to delete an existing database
testDB then DROP DATABASE statement would
be as follows:
SQL> DROP DATABASE testDB;

Syntax for Dropping Table:


DROP TABLE table_name;
Eg: Drop table student;
Database Management Systems Syed Nawaz(Asst Professor)
ALTER: It is used to alter the structure of the database
object. This change could be either to modify the
characteristics of an existing attribute or probably to add a
new attribute.
Syntax:
Data Definition To add a new column in the table
Language 1.ALTER TABLE table_name ADD column_name COLUMN-
Statements: definition;
To modify existing column in the table:
1.ALTER TABLE MODIFY(COLUMN DEFINITION....);
EXAMPLE
1.ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2
(20));
2.ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR
2(20));

Database Management Systems Syed Nawaz(Asst Professor)


TRUNCATE: It is used to delete all the rows from the table
and free the space containing the table.
Syntax:
1.TRUNCATE TABLE table_name;
Example:
Data Definition 1.TRUNCATE TABLE EMPLOYEE;
Language
Statements: DESCRIBE: It is used to describe the table
Syntax:
1.DESCRIBE TABLE table_name;
Example:
1.DESCRIBE TABLE EMPLOYEE;

Database Management Systems Syed Nawaz(Asst Professor)


Data Manipulation Language Statements (DML)
statements are used to put data, modify data and delete
data from the database tables. Different types of DML
commands are
SQL Languages
1. Insert
(DML):
2. Update
3. Delete
4. Select

Database Management Systems Syed Nawaz(Asst Professor)


INSERT: The INSERT statement is a SQL query. It is used to
insert data into the row of a table.
Syntax:
1.INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VA
Data LUES (value1, value2, value3, .... valueN);
Manipulation Or
Language
Statements: 2.INSERT INTO TABLE_NAME VALUES (value1, value2, val
ue3, .... valueN);
For example:
1.INSERT INTO javatpoint (Author, Subject) VALUES
("Sandy", "DBMS");

Database Management Systems Syed Nawaz(Asst Professor)


UPDATE: This command is used to update or modify the
value of a column in the table.
Syntax:
1.UPDATE table_name SET [column_name1= value1,...colu
mn_nameN = valueN] [WHERE CONDITION]
Data For example:
Manipulation 1.UPDATE students SET User_Name = 'Syed'
Language WHERE Student_Id = '3'
Statements:
DELETE: It is used to remove one or more row from a table.
Syntax:
1.DELETE FROM table_name [WHERE condition];
For example:
DELETE FROM java WHERE Author=“syed";

Database Management Systems Syed Nawaz(Asst Professor)


SELECT: This is used to select the attribute based on the
condition described by WHERE clause.

Syntax:
SELECT expressions
Data FROM TABLES
Manipulation WHERE conditions;
Language
Statements: For example:
SELECT emp_name
FROM employee
WHERE age > 20;

Database Management Systems Syed Nawaz(Asst Professor)


DCL commands are used to grant and take back authority
from any database user.
Here are some commands that come under DCL:

a. Grant
SQL Languages
b. Revoke
(DCL):
a.Grant: It is used to give user access privileges to a database.
b.Revoke: It is used to take back permissions from the user.

Database Management Systems Syed Nawaz(Asst Professor)


TCL commands can only be used with DML commands like
INSERT, DELETE and UPDATE only.
These operations are automatically committed in the
database that's why they cannot be used while creating
tables or dropping them. The commands include:
SQL Languages
•COMMIT
(TCL):
•ROLLBACK
•SAVEPOINT
a. Commit: Commit command is used to save all the
transactions to the database.
b. Rollback: Rollback command is used to undo transactions
that have not already been saved to the database.
c. Savepoint: It is used to roll the transaction back to a certain
point without rolling back the entire transaction

Database Management Systems Syed Nawaz(Asst Professor)


DBA, Designers
and End users

Database Management Systems Syed Nawaz(Asst Professor)


 The database administrator is a person having
central control over data and programs
accessing the data.
Database
 DBA coordinates all the activities of the
Administrator database system
 They are the users who are most familiar with
the database and are responsible for creating,
modifying, and maintaining the database.
 DBA is responsible for granting permission to
the users of the database and stores the profile
of each user in the database

Database Management Systems Syed Nawaz(Asst Professor)


 Schema definition
 Storage structure and access-method definition
 Schema and physical-organization modification
Functions/
 Granting of authorization for data access
 Routine maintenance
responsibility
Database
Administrator

Database Management Systems Syed Nawaz(Asst Professor) 81


 Database designers are responsible for
identifying the data to be stored in the
database and for choosing appropriate
structures to represent and store this
Database Designers data.
 It is the responsibility of database
designers to communicate with all
prospective database users in order to
understand their requirements, and to
come up with a design that meets
these requirements.
Database Management Systems Syed Nawaz(Asst Professor)
 End users are the people whose
jobs require access to the
database for querying, updating,
and generating reports.
End Users
 There are several categories of
end users:
 Naïve users
 Application Programmers
 Sophisticated end users
 Specialized users

Database Management Systems Syed Nawaz(Asst Professor)


 These are also called unsophisticated users.
 Naive users make up a sizable portion of
database end users.
 These users uses Application programs to
interact with the database.
End Users  Bank tellers check account balances and post
withdrawals and deposits.
 Reservation clerks for airlines, hotels, and car
rental companies check availability for a given
request and make reservations

Database Management Systems Syed Nawaz(Asst Professor)


 They are computer professionals
who write application programs
 They can choose many tools(RAD)
End Users to develop user interface which
enable them to construct forms and
reports .

Database Management Systems Syed Nawaz(Asst Professor)


 Sophisticated users are database developers
who write SQL queries to select/delete/update
the data.
 They do not use application programs to
request the data from database.
End Users  Interact by means of SQL.
 These users are scientists ,engineers and
analysts.

Specialized users
 Sophisticated users ,but they write special
database application programs that do not fit
into traditional data processing framework.
Database Management Systems Syed Nawaz(Asst Professor)
The Functional components of a
database system can be divided in to
Query Processor Components
Storage Manager Components
DBMS architecture

Database Management Systems Syed Nawaz(Asst Professor)


DBMS architecture

Dbms Architecture

Database Management Systems Syed Nawaz(Asst Professor)


The Query Processor Components include:
DDL interpreter:
 It interprets DDL statements and converts them in to
a set tables which are saved in the data dictionary
DBMS architecture DML compiler:
 It translates DML statements into low-level
instructions that are understood by the Query
Evaluation Engine.
 It also optimizes the DML Queries for efficient
execution by the Query Evaluation Engine.
Query evaluation engine:
 It executes low-level instructions generated by the
DML compiler and produces results.

Database Management Systems Syed Nawaz(Asst Professor)


 The storage manager components
include:
File manager:
DBMS architecture  It manages the allocation of disk-space
for the storage of DBMS files.
Buffer manager:
 It is responsible for fetching data from
disk storage into main memory buffers
for processing, and then writing the
updated data back onto the disk.

Database Management Systems Syed Nawaz(Asst Professor)


Authorization and integrity manager:
 It tests for the satisfaction of integrity
constraints and checks the authority of
DBMS architecture users to access data.
Transaction manager:
 This component ensures that
concurrent transactions proceed
without conflict and the database
remains in a consistent (correct) state
despite system failures.

Database Management Systems Syed Nawaz(Asst Professor)


Data files:
 Which stores the database itself.
Data dictionary:
 It is a metadata file, which stores the database
DBMS architecture schema. It stores metadata about the structure of
the database.
Indices:
 It can provide fast access to data items. Like the
index in this textbook, a database index provides
pointers to those data items that hold a particular
value.
Statistical data:
 It stores the statistical information about
processing of previous queries.
Database Management Systems Syed Nawaz(Asst Professor)
Phases of Database Design

Requirements collection and


analysis

Phases of Database Conceptual Database


Design Design

Logical Database Design

Schema Refinement

Physical Database Design

Application and security


Design

Database Management Systems Syed Nawaz(Asst Professor)


Requirements collection and Analysis:
In this step, the database designers
interview prospective database users to
Phases of
Database Design understand and document their data
requirements.
 These requirements should be
specified in - as detailed and complete
form as possible

Database Management Systems Syed Nawaz(Asst Professor)


Conceptual Database Design:
Once all the requirements have been collected and
analyzed, the next step is to create a conceptual schema
for the database; using a high-level conceptual data
Phases of model this step is called conceptual design.
Database Design The conceptual schema is a concise description of the
data requirements of the users and includes detailed
descriptions of the entity types, relationships, and
constraints; these are expressed by using the ER Model

Database Management Systems Syed Nawaz(Asst Professor)


Logical Database Design:
The next step in database design is the actual
implementation of the database, using a commercial DBMS.
Most current commercial DBMSs use an implementation
data model such as the relational or the object-relational
Phases of
database model.
Database Design In this phase the conceptual schema is transformed from the
high-level data model into the implementation data model

Database Management Systems Syed Nawaz(Asst Professor)


Schema Refinement:
 In this step, the relational database schema is analyzed to
identify the potential problems in it and then refine the
schema. This is done by normalization techniques
Phases of Physical Database Design:
Database Design  In this step the physical database is designed , during which
the internal storage structures, indexes, access paths, and
file organizations for the database files are specified.

Application and Security Design:


 Any software project that involves DBMS must consider the
aspects of application itself. Design methodologies like UML
will address this.

Database Management Systems Syed Nawaz(Asst Professor)


 Entity-Relationship model is a popular high, level
conceptual data model.
 ER Model is best used for the conceptual design of
ER Model database.
 The ER model describes data as entities, relationships,
and attributes.
 ER Model is based on: Entities and their attributes,
Relationships among entities

Database Management Systems Syed Nawaz(Asst Professor)


 An entity, which is a "thing" in the real world
with an independent existence.
 An entity may be an object with a physical
existence
ER Model
 for example, a particular person, car, house, or
employee
 It may be an object with a conceptual existence
 for example, a job, or a university course
 In the University database context, an individual
student, faculty member, a class room, a course
are entities

Database Management Systems Syed Nawaz(Asst Professor)


 Attribute describes property or characteristics of
an entity
 These are the properties of the entity.
 For example, an employee entity may be
ER Model
described by the employee's name, age,
address, salary, and job. A particular entity will
have a value for each of its attribute
Types of Attributes
1. simple versus composite
2. single-valued versus multivalued
3. stored versus derived.

Database Management Systems Syed Nawaz(Asst Professor)


 Composite attributes can be divided into smaller
subparts
 For example, the Address attribute of the employee
entity can be subdivided into StreetAddress, City,
ER Model State, and Zip,3 with the values "2311 Kirby,"
"Houston," "Texas," and "77001."
 Attributes that are not divisible are called simple or
atomic attributes.
 Ex: Zipcode

Database Management Systems Syed Nawaz(Asst Professor)


 Single-valued attribute is the attribute which is
having only single value.
 Most attributes have a single value for a
particular entity; such attributes are called
ER Model
single-valued.
 For example, Age, is a single-valued attribute of
a person.
 Multi-valued attribute is the attribute which is
having more than one value.
 an attribute can have a set of values for the
same entity-for example, a Colors attribute for a
car, or a phno attribute for a person.

Database Management Systems Syed Nawaz(Asst Professor)


Derived attribute is one whose value can be
calculated/derived from the values of other
attributes. The Age and BirthDate attributes of a
person.
ER Model  For a particular person entity, the value of Age can
be determined from the current (today's) date and
the value of that person's BirthDate.
The Age attribute is hence called a derived
attribute and is said to be derivable from the
BirthDate attribute, which is called a stored
attribute.

Database Management Systems Syed Nawaz(Asst Professor)


 It is Association among several entities.
 Relationship set: set of relationships of same
type or also called as relationship type.
 For example, the WORKS_ON relationship
type in which EMPLOYEEs and PROJECTs
participate, or the MANAGES relationship
type in which EMPLOYEEs and
DEPARTMENTs participate.
.
Database Management Systems Syed Nawaz(Asst Professor)
Database Management Systems Syed Nawaz(Asst Professor)
The degree of a relationship is the number of
participating entities.
It refers to number of entity sets that participate in a
relationship set.
ER Model The degree of WORKS-FOR relationship is two.
A Relationship type of degree one is called unary, a
Relationship type of degree two is called binary, and a
Relationship type of degree three is called ternary.
In ER diagrams, relationship types are displayed as
diamond-shaped boxes, which are connected by
straight lines to the rectangular boxes representing the
participating entity types.

Database Management Systems Syed Nawaz(Asst Professor)


 Relationship types usually have certain
constraints that limit the possible combinations
of entities that may participate in the
corresponding relationship set.
ER Model  For example if the company has a rule that each
employee must work for exactly one
department, then we would like to describe this
constraint in the schema.
 Two main types of relationship constraints
1. Cardinality ratio
2. Participation.

Database Management Systems Syed Nawaz(Asst Professor)


 The cardinality ratio for a binary relationship
specifies the maximum number of relationship
instances that an entity can participate in.
ER Model
 For example, in the WORKS_FOR binary
relationship type, DEPARTMENT: EMPLOYEE is
of cardinality ratio l: N, meaning that each
department can be related to any number of
employees but an employee can be related to
(work for) only one department.

Database Management Systems Syed Nawaz(Asst Professor)


For a binary relationship set the
mapping cardinality must be one of
ER Model
the following types:
 One to One(1:1)
 One to many(l:N)
 Many to one(N:l)
 Many to many (M:N)
 Consider binary relationship set R
between entity sets A and B

Database Management Systems Syed Nawaz(Asst Professor)


One to One: An entity in A is associated with at most
one entity in B, and an entity in B is associated with at
most one entity in A.
An example of a 1:1 binary relationship is MANAGES
ER Model which relates a department entity to the employee who
manages that department. This represents the mini-
world constraints that at any point in time-an employee
can manage only one department and a department has
only one manager.

Database Management Systems Syed Nawaz(Asst Professor)


 One to Many: An entity in A is associated with many
entities in B and an entity in B is associated with at most
one entity in A.
 Many to One: An entity in A is associated with at most one
ER Model entity in B, an entity in B is associated with many entities in
A.
 Ex: an employee works in a single department but a
department consists of many employees.

Database Management Systems Syed Nawaz(Asst Professor)


 Many to Many: An entity in A is associated with many
entities in B, and an entity in B is associated with many
entities in A.
 Ex: The relationship type WORKS_ON is of cardinality ratio
ER Model M:N, because the mini-world rule is that an employee can
work on several projects and a project can have several
employees.

Database Management Systems Syed Nawaz(Asst Professor)


 This constraint specifies the
minimum number of relationship
ER Model
instances that each entity can
participate in, and is sometimes
called the minimum cardinality
constraint.
 There are two types of participation
constraints
1. Total participation
2. Partial participation
Database Management Systems Syed Nawaz(Asst Professor)
Total participation:
 If a company policy states that every employee must work
for a department, then an employee entity can exist only
if it participates in at least one WORKS_FOR relationship
ER Model instance Thus, the participation of EMPLOYEE in
WORKS_FOR is called total participation, meaning that
every entity in "the total set" of employee entities must
be related to a department entity via WORKS_FOR. Total
participation is also called existence dependency.

Database Management Systems Syed Nawaz(Asst Professor)


 We do not expect every employee
to manage a department, so the
ER Model
participation of EMPLOYEE in the
MANAGES relationship type is
partial, meaning that some or "part
of the set of" employee entities are
related to some department entity
via MANAGES, but not necessarily
all.

Database Management Systems Syed Nawaz(Asst Professor)


Database Management Systems Syed Nawaz(Asst Professor)
 Entity types that do not have key attributes of their
own are called weak entity types.
 In contrast, regular entity types that do have a key
attribute are also called strong entity types.
ER Model  Entities belonging to a weak entity type are
identified by being related to specific entities from
another entity type in combination with one of their
attribute values
 Weak entity type always has a total participation
constraint (existence dependency) with respect to its
identifying relationship, because a weak entity
cannot be identified without an owner entity.

Database Management Systems Syed Nawaz(Asst Professor)


ER DIAGRAM – Relationship Types are: WORKS_FOR,
MANAGES, WORKS_ON, CONTROLS,SUPERVISION,
DEPENDENTS_OF

ER Model

Database Management Systems Syed Nawaz(Asst Professor)


 The ER model is generally sufficient for "traditional"
database applications.
 But more recent applications of DB technology (e.g.,
CAD/CAM, telecommunication, images/graphics,
EER Model multimedia, data mining/warehousing, geographic
info systems) cry out for a richer model.
 The EER (Enhanced ER) model includes all the
modeling concepts of the ER model ,In addition, it
includes the concepts of subclass and superclass and
the related concepts of specialization and
generalization.

Database Management Systems Syed Nawaz(Asst Professor)


An entity type is used to represent both a
type of entity and the entity set or collection
of entities of that type that exist in the
EER Model database.
Defining a new entity type from existing
entity types is called inheritance.
New entity type is called subclass and
existing entity type is called superclass

Database Management Systems Syed Nawaz(Asst Professor)


Database Management Systems Syed Nawaz(Asst Professor)
 The set of entities in each of the latter
groupings is a subset of the entities that
belong to the EMPLOYEE entity set,
meaning that every entity that is a
member of one of these sub groupings is
also an employee.
 We call each of these sub groupings a
subclass of the EMPLOYEE entity type,
and the EMPLOYEE entity type is called
the super class for each of these
subclasses
Database Management Systems Syed Nawaz(Asst Professor)
 Specialization is the process of
defining a set of subclasses of an
EER Model
entity type;
 That entity type is called the super
class of the specialization.
 The set of subclasses that form a
specialization is defined on the basis
of some distinguishing
characteristic of the entities in the
super class
Database Management Systems Syed Nawaz(Asst Professor)
 The term generalization to refer to the
process of defining a generalized entity
type from the given entity types.
EER Model  Generalization a reverse process of
abstraction in which we suppress the
differences among several entity types,
identify their common features, and
generalize them into a single super class
of which the original entity types are
special subclasses.

Database Management Systems Syed Nawaz(Asst Professor)


 Hence, in below Figure we can view {CAR, TRUCK}
as a specialization of VEHICLE, rather than viewing
VEHICLE as a generalization of CAR and TRUCK.
 Similarly, in previous figure we can view EMPLOYEE
EER Model as a generalization of SECRETARY, TECHNICIAN,
and ENGINEER.

Database Management Systems Syed Nawaz(Asst Professor)


EER Model

Database Management Systems Syed Nawaz(Asst Professor)


 Aggregation is a design strategy in which the
relationship is modeled between a collection
of entities and another relationship
 Simply it is used when we need Express a
relationship among other relationships

Database Management Systems Syed Nawaz(Asst Professor)


name
ssn lot

Employees

 Used when we have


to model a Monitors until

relationship involving Aggregation


(entitity sets and) a
started_on
relationship set. dname
pid pbudget did budget
 Aggregation allows us
to treat a relationship
Projects Sponsors Departments
set as an entity set for
purposes of
participation in (other)  Aggregation vs. ternary relationship:
relationships.  Monitors is a distinct relationship,

 Monitors mapped to with a descriptive attribute.


 Also, can say that each sponsorship
table like any other is monitored by at most one employee.
relationship set.

Database Management Systems Syed Nawaz(Asst Professor)


 Design choices:
 Should a concept be modeled as an entity or an
attribute?
 Should a concept be modeled as an entity or a
relationship?
 Identifying relationships: Binary or ternary?
Aggregation?

Database Management Systems Syed Nawaz(Asst Professor)


 Should address be an attribute of Employees or an
entity (connected to Employees by a relationship)?
 Depends upon the use we want to make of
address information, and the semantics of the
data:
▪ If we have several addresses per employee, address must be an
entity (since attributes cannot be set-valued).
▪ If the structure (city, street, etc.) is important, e.g., we want to
retrieve employees in a given city, address must be modeled as
an entity (since attribute values are atomic).
Database Management Systems Syed Nawaz(Asst Professor)
name from to
dname
 Works_In2 does not ssn lot did budget
allow an employee to
Employees Works_In2 Departments
work in a department for
two or more periods.
 Similar to the problem of
wanting to record several
addresses for an
name dname
employee: we want to ssn lot did budget
record several values of the
Employees Works_In3 Departments
descriptive attributes for
each instance of this
relationship. from Duration to

Database Management Systems Syed Nawaz(Asst Professor)


name
ssn lot pname age
 If each policy is Employees Covers Dependents
owned by just 1
Bad design
employee: Policies
 Key constraint on
policyid cost
Policies would
mean policy can name pname age
ssn lot
only cover 1
dependent! Dependents
Employees

Purchaser
Beneficiary

Better design
Policies

policyid cost
Database Management Systems Syed Nawaz(Asst Professor)
 Previous example illustrated a case when two binary
relationships were better than one ternary relationship.
 An example in the other direction: a ternary relation
Contracts relates entity set Parts, Departments and
Suppliers, and has descriptive attributes qty. No
combination of binary relationships is an adequate
substitute:
 S “can-supply” P, D “needs” P, and D “deals-with” S does not imply
that D has agreed to buy P from S.
 How do we record qty?

Database Management Systems Syed Nawaz(Asst Professor)

You might also like