100% found this document useful (1 vote)
4K views80 pages

Rdbms III Sem

1) The document provides an overview of relational database concepts and relational database management systems (RDBMS). 2) It discusses the evolution of database systems from traditional file-based systems to relational databases and more recent developments like object-oriented and XML databases. 3) The key advantages of RDBMS over file-based systems are improved data sharing, security, integration and access as well as reduced data redundancy and improved decision making.

Uploaded by

sms948072
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
4K views80 pages

Rdbms III Sem

1) The document provides an overview of relational database concepts and relational database management systems (RDBMS). 2) It discusses the evolution of database systems from traditional file-based systems to relational databases and more recent developments like object-oriented and XML databases. 3) The key advantages of RDBMS over file-based systems are improved data sharing, security, integration and access as well as reduced data redundancy and improved decision making.

Uploaded by

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

JAAGRUTHI DEGREE & PG COLLEGE

RELATIONAL
DATABASE
MANAGEMENT SYSTEM
BCOM CA I YEAR II SEMESTER
T.SRIKANTH LECT. IN COMPUTERS

2018

AZAD ROAD BHONGIR NALGONDA (D)


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

UNIT-1
DATABASE CONCEPTS

Data:
Data is nothing but a collection of raw facts of a person or a thing.
Ex : collection of numbers , characters and text.

Information:
Information is nothing but from which the data can be derived. The processed
data is also known as information.

Meta Data:
Meta data is data about data. (Or) metadata is data that describes other data.
It tells us how, when and by whom the data is modified.

Data Base:
Data base is an organized collection of data.
(Or)
Data base is a collection of inter-related information which is stored in a well
arranged manner.
The aim of the database is to organize huge amount of information in
an efficient manner.
DBMS:
Database management system is a collection of inter-related data and a set of
programs, which are stored, processed and retrieved (accessed).

DBMS is designed in such a way that data is stored at a cheaper rate


and it is accessed in less amount of time.

The following are the various databases:

i) Ms-Access.
ii) Oracle.
iii) Sybase.
iv) Db2.
v) Tera data
vi) SQL server.
vii) Fox pro.

Relational Database:
Relational data base is an organized collection of logically related data.
(Or)

A relational database is a database that stores information about both the data
and its relation. In relational database, the data is organized in the form of tables.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 2


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

RDBMS:-
A relational database management system is a database management
system that is based on the relational model introduced by E.F.Codd.
RDBMS is used for storage of information in new database used for financial
records, manufacturing and personnel data. Relational databases are easy to
understand and use. Many popular databases are based on the relational database
model.

Evolution of Database System:


Before the use of data bases, people worked with files. The file
management system stores all the data in a single large file.
The main disadvantage of this system is searching a record or data takes
a long time. The drawbacks of file management system are updating or modifying
the data cannot be done easily, sorting the records takes long time.
So the database systems are introduced for efficient storage updating, sorting
the data.
1960’s 1970’s 1980’s 1990’s 2000+

Hierarchical XML
Object Oriented

Traditional Files Relational

Network Object Relational

1960’s:
Databases were first introduced in 1960’s. In mid-1960’s there were a number
of general purpose database systems. Data was stored in magnetic tapes.
1970’s:
The Hierarchical and Network data models were developed for invoices & bills
of different goods.
1980’s:
Edgar F. Codd proposed a new model called Relational data model. A new
database was developed called as Relational database.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 3


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

1990’s:
In 1990’s Object oriented & Object relational databases were developed. Data
in the database is treated as object.
Today:
In this decade, non-relational databases are used like XML database.

FILE ORIENTED(BASED) SYSTEMS


File oriented system is an earlier system to databases. The typical file
oriented system is supported by a conventional operating system. Permanent
records are stored in various files and a number of different application programs are
written to extract records from and add records to appropriate files.
The following are the disadvantages of file oriented system:
1. Data Redundancy and Inconsistency:
Since files and application programs are created by different
programmers, the files will have different formats and programs may be
written in several programming languages. The same piece of information
may be duplicated in several places. This redundancy leads to higher storage,
access cost and may lead to data inconsistency.
2. Difficulty in accessing data:
The conventional file processing environments do not allow needed
data to be retrieved in a convenient and efficient manner. Better data retrieval
systems must be developed for general use.
3. Data Isolation:
Since data is scattered in various files and files may be in different
formats, it is difficult to write new application programs to retrieve the
appropriate data.
4. Concurrent access anomalies:
In order to improve the overall performance of the system and obtain a
faster response time, many systems allow multiple users to update the data
simultaneously. In such environment, interaction of concurrent updates may
result in inconsistent data.
5. Security problems:
Not every user of the database system should be able to access all the
data. It is difficult to enforce security constraints in file oriented systems.
6. Integrity problems:
The data vales stored in the database must satisfy certain types of
consistency constraints. These constraints are enforced in the system by
adding appropriate code in the various application programs. When new
constraints are added, it is difficult to change the programs to enforce them.
7. Atomicity problems:
A computer system may fail. In many applications it is crucial to ensure
that once a failure has occurred and has been detected, the data are restored
to the consistent state existed before the failure.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 4


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Advantages of DBMS over File based system:

DBMS provides the following advantages compared with file based


system.
1. Improved Data Sharing:
The DBMS offers access to more data. It offers data sharing among its
users.
2. Improved Data Security:
Accessing the data by many users gives risks to the data security. So
DBMS provides better data privacy & security policies.
3. Minimized data redundancy:
Data inconsistency exists when different version of the same data
appears in different places. DBMS greatly reduced data inconsistency.
4. Better data integration:
DBMS provides an integrated view of the entire organization. It
integrates the data of all the departments and maintains it as one data set.
5. Improved data access:
The DBMS provides quick answers to queries. A query is a data
manipulation request issued to the DBMS.
6. Improved decision making:
Better managed data provides better quality information and
knowledge. It is useful to make better decision.
7. Increased end-user productivity:
The availability of data and information increases end-user productivity.

DATA MODELS:

Data model is nothing but high level description of data

(Or)

A conceptual method of structuring data is called “Data Model”.

Data models are classified into five types. They are:

1) Entity- Relationship model


2) Object oriented model
3) Relational model
4) Hierarchical model
5) Network model
1) ER MODEL:-
The entity relationship data model is based on the real world objects
called “entities” and relationship between these objects. ER model is graphically
represented by an ER diagram.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 5


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

The following are the components of ER diagram.


Rectangle represents an entity set.
Ellipses represent a list of attributes.
Diamond represents relationship among the entities.
Lines represents link between attributes to the entity sets and entity
sets to relationship.

B name
C name
B id
Cid B address
C address

borrows from
CUSTOMER LOAN BANK

B Mobile B branch
Salary
Mobile no

2) Object oriented model:-


Object oriented model is based on collection of objects like ER model.
An object contains values stored in instance variable within the object. An object
also contains methods to operate on the object. Objects containing same type of
values and same methods are combined into classes.

CUSTOMER

Cust_no

Cust _name

Cust_address

Methods()
3) Relational model :-
The relation model uses a collection of tables to represent both the
data and relationships. In this data, each table has multiple columns and each
column has a unique relation. Here, relation refers to a two-dimension table
containing rows and columns of the data.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 6


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

CUSTOMER TABLE
Cust – no Cust – name Cust – address

11500 Anil Hyd


11501 Balu Mumbai
11502 Chandana Delhi
11503 Divya Kolkata
11504 Eshwar Chennai

4) Hierarchical model:-
Data in hierarchical model is represented as collection of records and
relationships among data are represented as links.

CUSTOMER

11500 Anil Hyd 11501 Balu Mumbai

A-101 1000 A-102 5000

The records in the database are organized as collection of trees.

5) NETWORK MODEL:-
Data in the network model is represented as collection of records and
relationship among data is represented by lines. The records in the database
are organized as collection of arbitrary graphs.

11500 Anil Hyd A-101 1000

11501 Balu Mumbai A-102 5000

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 7


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

DATABASE ADMINISTRATOR (DBA):

DBA is the person who is responsible for complete maintenance and effective
working of the database. DBA is also responsible for managing databases.
ROLES OF DBA:
The following are the roles of DBA.
Database design:
Design is of two types
1) Conceptual design
Conceptual data base design consists of data definitions, relationship
between data.
2) Physical design
Physical database design determines the physical structure of
database and access methods.
User Training:
The DBA is responsible for providing guide lines to the user. Training
sessions, user manuals and help line centers are provided to user about details of
database creation.
Database Security and Integrity:
DBA controls data access by using authentication and authorization.
--Authentication is the process of checking whether the user is valid or not
--Authorization is the process of verifying the permissions of a valid user.
The DBA is responsible for giving passwords & controlling privileges.
Data Integrity means the problems of maintaining the accuracy and consistency of
data values.
Database System Performance:
The DBA should include technical people to identify and solve system
response-time problems. The DBA may maintain redundant/duplicate copies of data
at different locations/places to improve the system performance.

Functions of DBA:
The following are the functions of a DBA:
1. Schema Definition:-
The DBA creates database schema by executing DDL statements.
Schema includes the logical structure of database.

2. Data Definition:-
The DBMS provides functions to define the structure of the data in
application. It includes defining and modifying record structure, type and size
of fields.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 8


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

3. Data Manipulation:-
Once data structure is defined, data needs to be inserted, modified or
deleted. The functions which perform these operations can handle planned and
unplanned data manipulation needs.
4. Granting authorization for data access:-
The DBA provides different access rights to the users according to their level.
5. Routine Maintenance:-
Some of the routine maintenance activities of a DBA are given below.
 Taking back up of database.
 Ensuring enough disk space.
 Ensure that performance is not degraded.
 Performance tuning.
6. Security:-
The DBA focuses on security methods to prevent unauthorized users
from accessing the database.
7. Backup and Recovery:-
Backup and recovery procedures are tested regularly to maintain
effectiveness in restoring database after failure.
8. Performance Evaluation:-
System performance is monitored by collecting statistics on transaction
volume, response time, error rates.
9. Integrity Checking:-
Schedules have been developed for testing the integrity of the data
stored in the database.

DATABASE APPROCH:
Database approach is a way in which data is stored in the database.
Sharability:
Sharability means the same data can be used at the same time for different
processes by different people.
Availability:
Availability means data should be made available when and where it is
needed and also in different formats.
Data Independence:
Data independence means the ability to modify a schema definition in one
level without effecting the schema definition in the next level. Schema means the
overall design of the database.
There are two levels of data independence.
--Physical Data Independence:
The ability to modify the physical schema without rewriting the
application programs.
--Logical Data Independence:
The ability to modify the conceptual schema without rewriting the
application programs.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 9


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Data Integrity:
The DBMS enforces integrity rules to minimize data redundancy and
maximize data consistency. The data relationships are used to enforce data integrity.

ADVANTAGES OF DATABASE APPROACH:


The following are the advantages of database approach.
1) Program Data Independence:
The database allows data to change the data base without modifying
the application programs. This allows separation of database from the
application programs.
2) Minimal Data Redundancy:
The database approach does not eliminate redundancy completely,
but it provides the facilities to the designer to control the amount of
redundancy.
3) Improved Data Consistency:
If the amount of data redundancy is controlled, it will improve data
consistency. It is better to maintain the same version of the data at all the
locations.
4) Improved Data Sharing:
A data base is designed as a sharable component. The DBMS
helps end users to have better access for data and to manage data.
5) Enforcement Of Standards:
Every DBA designs procedures and enforcement of standards for
database management. Procedures are the instructions and rules for the
design and use of the database system. Procedures are used to enforce the
standards by which business is generated within the organization and with
customers
6) Improved quality:
The database approach provides tools & processes to improve data
quality. The availability of data combined with tools that transform data into
usable information empowers end users to make informed decisions.
ER Model:-

The ER (Entity-Relationship) model is based on real world objects called


entities and relationship among these objects. The basic elements of ER model are
entity, attribute and relationship.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 10


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

-Entity:-
An entity is a real world object. An entity is represented by a rectangle. An
entity can be a person, place or object.
Ex: A human being, computer, bike.
-Entity set:-
A collection of similar entities is called entity set or entity type.
Ex: All employees of an organization EMP.
All departments of a university DEPT.
Types of Entities:-
--Weak Entity:-
Weak entity is an entity that depends on other entity or entities.
The weak entity is shown in double rectangle box.
--Strong Entity:-
A strong entity is an entity that does not depend on other entity
or entities.

FATHER

FAMILY

In above diagram, “Father” is a strong entity and “Family” is a weak entity.

-Attribute:-

An attribute is a property or characteristic of an entity. It is used to describe


entities

Types of Attributes:-

--Simple attribute:-
If an attribute cannot be divided into simpler components, it is a simple
attribute.
Ex:- EmpNo, StdNo
--Composite attribute:-
If an attribute can be divided into components, it is called a composite
attribute.
Ex:- Name of student can be divided into First-name and Last-name
--Single-Valued attribute:-
If an attribute can take only a single value, it is a single valued attribute.
Ex:- age of a student

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 11


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

--Multi-Valued attribute:-
If an attribute can take more than one value, it is a multi-valued
attribute. Multi-valued attribute is represented with double ellipse.
Ex:- Telephone number (Mobile number, Landline)

--Derived attribute:-
An attribute which is calculated or derived from other attributes is called
a derived attribute. Derived attribute is represented with dashed ellipse.
Ex:- Total and average are calculated on marks of the student.

Relationship:
A relationship is an association of two or more entities. A meaningful
relationship is called relationship set or relationship type.
Ex:- Working is a relationship between EMP and DEPT
Degree of Relationship:-
Relationship degree means the number of entities in a relationship.
Relationships can be classified by their degree.
Unary Relationship:-
In unary relationship, there is only one entity.

ENTITY

Binary Relationship:-
In binary relationship, two entities are involved.

Relation
ENTITY -ship
ENTITY

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 12


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Ternary Relationship:-
In ternary relationship, three entities are involved.

Relation
ENTITY -ship
ENTITY

ENTITY

n-ary Relationship:-
In this relationship, four or more entities are involved.

ENTITY

Relatio
ENTITY n-ship
ENTITY

ENTITY

RELATIONAL DATA MODEL:


The primary concept of relational data model is a relation. Relations are same
as tables.
A relation contains the following rules:
Relation is a two-dimensional table.
Attribute (field) is a column in the table.
Entries in any column are all of the same type.
A tuple (record) is a row in the table.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 13


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

--Key:-
It is an attribute used to identify data in a relation.
--Simple Key:-
A simple key contains a single attribute in a relation.
--Composite Key:-
It contains more than one attribute.
--Super Key:-
It is a set of attributes of a relation variable for which in all relations assigned
to that variable, there are no two distinct tuples that have the same values for the
attributes in this set.
--Candidate Key:-
It is an attribute that uniquely identifies a row.
--Primary Key:-
A primary key is the candidate key which is selected as the principal unique
identifier.
Ex:- stdno in student relation
--Foreign Key:-
It is an attribute that is a non key attribute in one relation and as a primary key
attribute in another relation.
Ex:- In EMP table, ‘dept-no’ is a foreign key which is already a primary
key in DEPT table.
--Alternate Key:-
It is a candidate key which is not selected to be the primary key.
Ex:- If user forgets his registration number in an application, name &
date of birth is an alternate key.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 14


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

UNIT-2
DATABASE INTEGRITY AND NORMALIZATION

INTEGRITY CONSTRAINTS:
Integrity constraint ensures that changes made to the database by authorized
users do not result in loss of data consistency. A relational data model includes the
following constraints.
--Domain constraint
--Entity Integrity
--Referential Integrity
--Operational constraints
Domain Constraint:-
Domain is a set of atomic data values with unique data type in relational
database. Domain constraint is used to validate data when Insert or Update
statement is executed in the relational database.
Ex:- Not Null, Default and Check are domain integrity constraints.
--Not Null Constraint:-
NULL in SQL indicates data which does not exist in the database.
NULL concept was introduced by E.F.Codd to represent missing data in the
relational database model.
By default, all columns can store with NULL data value. NOT NULL
constraint is used to define the column that needs data value.
--Default Constraint:-
Default constraint is used to define a default number, string, date in the
mandatory column. Default data must match with data type and range of the
mandatory column.
--Check Constraint:-
Check constraint is used to define a logical expression that valid data
when Insert or Update data is performed in a table of relational database.
Entity Integrity:-
An entity is an object in the real world. Set of attributes whose values uniquely
identify a record of relation is called key. Each relation must have one key. This key
can be either primary key or unique key.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 15


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

--Primary Key Constraint:-


It is used to define with one column or set of columns that uniquely
identify a record and avoids duplicate records of table. Each table can have
only one primary key constraint.
--Unique Key Constraint:-
It is used to define with one column or set of columns that uniquely
identify a record and avoids duplicate records of table. Unique constraint
accepts NULL data. Each table can have one or more than one unique
constraint. It helps to define alternative key in database.
Referential Integrity:-
It ensures set of attributes, data values that appears one relation into another
relation with common set of attributes. Referential integrity rules guarantee the
relationship in relational database model.
A foreign key is used to define referential integrity constraint which reference
a referenced key in relational database.
Referenced key is used to define referential integrity constraint with unique or
primary key that is referenced by foreign key in relational database.
Operational Constraints:-
Business rules are called operational constraints. Business rules are defined
according to the structure of the organization. It allows the designer to develop the
proper relationship between the data. It helps in a communicating tool between the
user and designer. It allows the designer to understand the nature and scope of the
data.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 16


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

NORMALIZATION:
Normalization is a process of decomposing the relations with anomalies
to produce smaller and well-structured relations.
(or)
Normalization is a process of evaluating table structures to minimize
data redundancy and reduce data anomalies.

Table with Multi


Valued Attributes
Remove multi
valued attributes &
define PK
FIRST NORMAL FORM
(1NF)

Remove Partial
dependency

SECOND NORMAL
FORM (2NF)
Remove Transitive
dependency

THIRD NORMAL FORM


(3NF)
Make every
determinant as
candidate key
BOYCE CODD NORMAL
FORM (BCNF)
Remove multi
valued
dependencies
FOURTH NORMAL
FORM (4NF)

Remove any
remaining
FIFTH NORMAL FORM anomalies
(5NF)

Functional Dependency:
A functional dependency is a constraint between two or more attributes
in which the value of one attribute is determined by the value of another
attribute.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 17


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

In a relation ‘R’, attribute ‘B’ is functionally dependent on attribute ‘a’ if


each and every value of ‘B’ is determined by the value of ’A’.
A functional dependency in a relation is represented by an arrow().
Determinant:
An attribute which determines the value of another attribute is called
determinant. It is an attribute in a functional dependency and can be
represented on the left side of the arrow.
Eg:
Consider the following relation STUDENT

SNO SNAME COURSE FEE


LANGUAGE KNOW N

The functional dependency in this relation can also be shown as:

Sno, languages-known sname, course, fee

Here, sno, languages-known are determinants

Sname, course, fee are dependants

Here, the comma(,) between the attributes in functional dependency


stands for a logical operator.

Partial dependency:
A partial dependency is a functional dependency in which one or more
non key attribut5es are functionally dependent on part of the primary key.
Transitive dependency:
A transitive dependency is a functional dependency that exists between
two or more non key attributes.
Multi valued dependency:
It is a dependency that exists when there are at least 3 attributes
(A,B,&C) in a relation with a well defined set of B & C values for each ‘A’
value. Here B & C values are independent of each other.
Normalization works through a series of stages. Each stage in a
normalization process is known as a normal form. A normalization process
consists of 6 normal forms.
1) First Normal Form (1NF)

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 18


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

2) Second Normal Form (2NF)


3) Third Normal Form (3 NF)
4) Boyce-Codd Normal Form (BCNF)
5) Fourth Normal Form (4NF)
6) Fifth Normal Form (5NF)
1) First Normal Form:
A relation is said to be in 1NF if it has no repeating groups (multi
valued attributes) and a primary key is defined.
Consider the following relation STUDENT:

SNO SNAME COURSE LANGUAGE FEE


KNOWN
101 Arun Bcom Telugu 18000
Hindi
English
102 Bharath Bcom Tamil 18000
Telugu
English
103 Charan Bcom English 18000
104 David Bcom English 18000
Malayalam
Telugu
The above relation ‘STUDENT’ is not in 1NF because it contains
repeating groups and also a primary key is not defined.
A relation can be converted into 1NF by using a two step process.
Step1:
Create a new row for each value of the multi valued attributes and
supply missing values.
Step2:
Define an appropriate and suitable primary key for the relation.
For the above relation ‘STUDENT’ sno, language known
are to be selected as a composite primary key.
As per step1, step2 STUDENT relation can be revised as:
SNO SNAME COURSE LANGUAGE FEE
KNOWN
101 Arun Bcom Telugu 18000
101 Arun Bcom Hindi 18000
101 Arun Bcom English 18000
102 Bharath Bcom Tamil 18000

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 19


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

102 Bharath Bcom Telugu 18000


102 Bharath Bcom English 18000
103 Charan Bcom English 18000
104 David Bcom English 18000
104 David Bcom Malayalam 18000
104 David Bcom Telugu 18000

Now the relation ‘STUDENT’ is in 1NF.


2) Second Normal Form:
A relation is said to be in 2NF if it is in 1NF and does not contain
any partial dependency.
Consider the following relation ‘STUDENT’

PRIMARY KEY

SNO COURSE
LANGUAGE
SNAME FEE
KNOWN

PARTIAL DEPENDENCY

The above relation is in 1NF but it contains partial dependency.


There is a process to convert a relation into 2NF.
Move the non key attributes (dependents) to new relation. Then
the ‘STUDENT’ relation can be decomposed into 2 new relations as
‘STUDENT’ & ‘STUDENT-LANG’ as shown below:

STUDENT

SNO SNAME COURSE FEE

STUDENT-LANG

SNO LANGUAGE KNOWN

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 20


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Now the above relations are in 2NF.

3) Third Normal Form (3NF):


A relation is said to be in 3NF if it is in 2NF and it should not
contain any transitive dependency.
Consider the following relation ‘PRODUCT’

PRODUCT

C-ID C-NAME
P-ID P-DESC P-PRICE P-QTY C-CITY

The above relation PRODUCT has transitive dependency as shown


below:

c-idc-name, c-city
For the above relation, c-name, c-city are dependent on c-id
which is a non key attribute. This is a transitive dependency. There is a
3 step process to convert a relation into 3NF.
Step1:
Create a new relation for each determinant in the table. This
determinant will act as a primary key for new relation.
Step2:
Move the attributes that are dependent on this determinant from old
relation to new relation.
Step3:
Leave the attribute (a determinant) which is a non key attribute) in old
relation to serve as a foreign key.
As per these steps, the PRODUCT relation can be decomposed into 2
relations, PRODUCT, CUSTOMER as below:

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 21


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

PRODUCT

P-QTY
P-ID P_DESC P-PRICE C-ID

CUSTOMER

C-ID C-NAME C-CITY

Boyce-Codd Normal Form:


Sometimes even though a relation is in 3NF, anomalies may still
exist.
R.F.Boyce and E.F.Codd identified the problems in 3 NF and
proposed a stronger definition to it known as BCNF.

A relation is said to be in BCNF if it is in 3NF and if and only if


every determinant is a candidate key.

Consider the following relation TIME TABLE

SECTION SUBJECT FACULTY TIME

A Physics Prasad 8am


B Maths Kiran 9am
C Physics Prasad 11am
D Computers Ramu 10am
E Maths Kiran 10am

The above relation is in 3NF but it contains a new kind of


dependency.
Here a key attribute (subject) is determined by a non key attribute
(faculty). This dependency can be removed by the following process:
Revise the relation and make the determinant (faculty) as a key
attribute then the attribute subject becomes a non key attribute.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 22


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

It gives the following relation.

SECTION FACULTY SUBJECT TIME

PARTIAL DEPENDENCY
The table contains partial dependency. It can be removed by
decomposing the table into 2 tables as shown below:
TIME TABLE

SECTION FACULTY TIME

FACULTY

FACULTY SUBJECT

Now these two relations are in BCNF.


4) Fourth Normal Form (4NF):
A relation is said to be in 4NF if it is in BCNF and it
does not contain multi valued dependencies.
Consider the following relation:

COURSE FACULTY BOOK

Java Kiran Dietel


Ramu Balaguruswamy
Raju
Oracle Ajay Peter
Codd Norton

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 23


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

After removing the multiple values for attributes the relation becomes as
below:
COURSE FACULTY BOOK

Java Kiran Dietel


Java Kiran Balaguruswamy
Java Ramu Dietel
Java Ramu Balaguruswamy
Java Raju Dietel
Java Raju Balaguruswamy
Oracle Ajay Peter
Oracle Ajay Norton
Oracle Codd Peter
Oracle Codd Norton
To remove the multi valued dependency, we have to decompose
the table into 2 relations as shown below:

COURSE FACULTY

FACULTY BOOK

FILE ORGANIZATION:
File organization is a way of arranging files on the disk and access method
tells how data is retrieved based on file organization.
File organization is the arrangement of files on the disk. It includes the way
how records and blocks are placed on storage medium. File organization is the
method of accessing and retrieving the record from the database.
A DBMS supports several file organization techniques. The important task of
DBA is to choose a good organization for each file based on its type of use.
Seven organization models are used to access file from the secondary
memory device with various techniques.
1. Sequential

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 24


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

2. Index-sequential
3. Hashed/Direct
4. Multi-key
5. Multi-list
6. Inverted
7. Heap
1. Sequential File Organization:
In sequential file organization, records are arranged sequentially. A
magnetic tape file such as printer can only have a sequential organization. A
sequentially organized file may be stored on either a serial-access or direct
access storage medium.
The task of file handling is the responsibility of the system software known
as Input-Output Control System (IOCS). Block is used to group a number of
consecutive records. IOCS take scare of blocking.
Beginning of file End of file

RECORD RECORD RECORD ………. RECORD RECORD


1 2 3 (n-1) n

Advantages of sequential file organization:-


i) Simple to implement
ii) Requires very low software support
iii) Efficiency of blocking is good
iv) Blocking saves input-output time required for handling a file
v) Storage space can be saved.
Disadvantages of sequential file organization:-
i) Updates are not easily done.
ii) Random access is not possible.
iii) Every record must be rewritten to provide space for new field.
Area of Use:-
Sequential files are most frequently used in commercial batch oriented data
processing applications.
Ex: Payroll applications

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 25


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

2. Index Sequential File Organization:


To improve the query response time of a sequential file, a type of indexing
technique can be added. When there is need to access record sequentially by some
key value and also to access records directly by the same key value, the collection of
records may be organized in an effective manner called index sequential file
organization.
An index is a set of index value and address pairs. A sequential file that is
indexed on its primary key is called an index sequential file. The records are stored
sequentially by primary key values and there is an index built over the primary key
field.
In index file organization, the records are stored in key sequence order
usually in ascending order. Some index tables are also created and maintained with
the file. Index table is used to identify the group of records in the file.

Sequential Index File Sequential Index File


n= number of records
Name$
Names$ (1)
Record number (1) Address$
Record 1
 City-state$
 Zip code$

 Name$

Name$ (n) Address$


Record 2
Record number (n) City-state$
Zipcode$


Record 3

Advantages of index sequential file organization:-


i) In index sequential file organization, the item in the table can be examined
sequentially.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 26


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

ii) It is very useful when a random access of records by specifying the key is
required.
iii) Updating is easily done.
Disadvantages:-
i) Performance decreases as file grows.
ii) Must follow index structure to locate data.
iii) Expensive system accessories.
Area of Use:-
It supports applications that access individual records rather than searching
through the entire collection in sequence.
Ex: Reservation Enquiry system
3. Hashed/Direct Access File Organization:
Direct file organization also referred as random or relative organization. Files
in this type of organization are stored in a direct access storage device (DASD) like
magnetic disk using an identifying key. This identifying key gives the actual storage
position of record in the file. The system can directly locate the key to find the
desired record without searching any other records.

1 Rec001

2 Free

3 Rec003

4 Rec004

Free
5
Relative Free
Record 6
Rec007
Number 7

325 Rec325

Rec326
326
Free
327
Rec328
328

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 27


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

It is used in online systems where rapid response and fast updating are
important compared to sequential access file organization. To access a record, the
CPU can go directly to the desired record without searching all the other records in
the file. Direct access is used where file activity is low.
Advantages:-
i) Immediate access to records for updating is possible.
ii) Transactions need not be stored.
iii) Different discs are not required for updating records.
iv) Random inquiries in business situations can be easily handled.
Disadvantages:-
i) Data may be accidentally erased or over-written.
ii) Less efficient in the use of storage space.
iii) Expensive hardware and software are required.
iv) System design is complex and costly.
v) File updating is more difficult compared to sequential files.
Area of Use:-
A direct file organization is suitable for interactive online applications such as
airline and railway reservation systems.
4. Multi-Key File Organization:

Multi key file organization is used to access the records by using more than
one key. It allows multiple access paths each having a dissimilar key. There are
several methods used to execute multi key file organization. Most of these
methods are based on building indexes to provide direct access by the key value.
Two of the common methods for this organization are:
Multi-list file organization
Inverted file organization
5. Multi-List File Organization:
Multi list file organization is a multi-index linked file organization. In a multi list
organization, indexes are defined on the multiple fields that frequently used to
search the record.
In the following diagram, one index has been defined on the field Book ID and
another on Category.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 28


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

6. Inverted File Organization:


Like multi-lists structure, inverted list structures can also maintain multiple
indexes on the file. The only difference is that instead of maintaining pointers in
each record as in multi-lists, indexes in the inverted file maintain multiple pointers
to point to the records.

7. Heap File Organization:


Heap Files:
A heap file is an unordered set of records. The following are the operations
supported:
Heap files can be created and destroyed.
Existing heap files can be opened and closed.
Records can be inserted and deleted.
Records are uniquely identified by a record id.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 29


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Heap file organization is the simplest file organization. Here records are
inserted at the end of the file. Once the data block is full, the next record is stored in
the new block. This method can select any block in the memory to store the new
records.
When a new record has to be retrieved, we need to search from beginning of
the file. Similarly, if we want to delete or update a record, we need to search for the
record from the beginning of the file and we can delete and update the record.

If a new record is inserted then in above diagram it will be inserted into the
data block1.

Advantages:
1. Very good method for bulk insertion.
2. Fetching of records is faster in small files.
Disadvantages:
1. It is not suitable for larger files.
2. No proper memory management.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 30


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

UNIT-3
SQL-STRUCTURED QUERY LANGUAGE

SQL stands for “Structured Query Language”. It is a query language used for
accessing and modifying information in the database. IBM first developed SQL in
1970’s.
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 time. Few functions
of SQL are:
 Store data
 Modify data
 Retrieve data
 Delete data
 Create tables and other database objects
SQL Environment:
 Catalog:-
A set of schemas that describes database is called a catalog.
 Schema:-
It is a structure that contains description of objects.
 Data Definition Language (DDL):-
Commands that define database which includes creating, altering and
dropping tables.
 Data Manipulation Language (DML):-
Commands that maintains and query a database.
 Data Control Language (DCL):-
Commands that controls a database including, administrative privileges and
committing data.
Role of SQL in Database Architecture:-
The Oracle RDBMS is available on many operating system platforms.
 Oracle is a relational DBMS- even the data dictionary is simply a collection
of tables of data along with indexes and other objects.
 SQL has a basic grammar and syntax.
 The functionality of SQL language is same on these operating system
platforms.
 Using SQL does not require programming experience.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 31


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

SQL Standards – their Characteristics and Benefits:-


The SQL standard provides:
 Specific syntax and semantics of SQL data definition & data manipulation
languages.
 Basic data structures and operations.
 Portability of applications.
 Reduced training cost.
 Productivity.
 Reduced dependence.

DATABASE SCHEMA:
In a relational database, the schema defines tables, fields in each table and
relationships between fields and tables. Schemas are generally stored in a data
dictionary.
Levels of database schema:-
1. Conceptual schema: a map of concepts and their relationships.
2. Logical schema: a map of entities, attributes and relations.
3. Physical schema: a particular implementation of a logical schema.
4. Schema object, Oracle database object.
5. Schema is the overall structure of the database
Each Data Schema includes:-
o A list of variables with description, definition and format.
o A list of domains with definition.
o A list of themes and modules with definitions.
SQL TABLES:
In relational databases, a table is a set of values that is organized using a
model of vertical columns and horizontal rows. A table has a specified number of
columns but can have any number of rows.
In database terms, a table is responsible for storing data in the database.
Database tables consist of rows and columns. Row contains each record in the table
and column is responsible for defining the type of data.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 32


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

SQL DATA TYPES:-


Data stored in a relational database can be stored using a variety of data
types. The primary Oracle data types are NUMBER, VARCHAR and CHAR for
storing numbers and text. Every constant, variable and parameter has a data type.
SQL provides many predefined data types and subtypes. A subtype is a
subset of another data type which is called as base type.
CHAR:-
It is used for storing fixed length character strings. If this type is used to
store variable length strings, it will waste a lot of disk space.
VARCHAR:-
Strings range from a single word or character to large blocks of text
including multiple paragraphs and unique symbols.
NUMBER:-
In SQL, decimals are referred as floating point numbers. These data
types are different from normal integer data types.
DATE:-
Data types used to store date and time values in DD-MM-YY
HH:MM:SS format.
BOOLEAN:-
Boolean values are true/false types of data. A Boolean table column
will contain either string values of “True” and “False” or numeric
representation with 0 for false or 1 for true.
RAW:-
A data type used to store binary data or data which is byte oriented.
RAW data can only be queried or inserted but cannot be manipulated. In SQL
its maximum size is 2000 bytes.
Difference between CHAR, VARCHAR & VARCHAR2:
CHAR:-
a. Fixed length memory storage
b. CHAR takes 1 byte per character
c. Use char when the data values in a column are of same size.
VARCHAR:-
a. Variable length memory storage.
b. VARCHAR takes 1 byte per character and 2 bytes to hold length
information.
c. Use VARCHAR when data values in a column are expected to change
in size.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 33


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

VARCHAR2:-
a. A replacement for VARCHAR in new versions of oracle.
b. VARCHAR can store up to 2000 bytes of characters while VARCHAR2
can store up to 4000 bytes of characters.
c. If VARCHAR is used in declaration then it will occupy space for NULL
values. In case of VARCHAR2 data type, it will not occupy any space.

SQL COMMANDS:
SQL commands are instructions used to communicate with the database to
perform specific task that work with data. SQL commands help user to interact with
SQL applications.
SQL commands are grouped into 4 major categories depending on the
functionality:
Data Definition Language (DDL) Commands:-
These SQL commands are used for creating, modifying and dropping
the structure of database objects. The commands are CREATE, ALTER,
DROP, RENAME and TRUNCATE.
Data Manipulation Language (DML) Commands:-
These SQL commands are used for storing, retrieving, modifying and
deleting data. These commands are SELECT, INSERT, UPDATE and
DELETE.
Data Control Language (DCL) Commands:-
These SQL commands are used for providing security to database
objects. These commands are GRANT and REVOKE.
Transaction Control Language (TCL) Commands:-
These SQL commands are used for managing changes affecting the
data. These commands are COMMIT, ROLLBACK and SAVEPOINT.

SQL COMMANDS

DDL DML DCL TCL

Create Insert Grant Savepoint


Alter Update Revoke Rollback
Truncate Delete Commit
Drop Select
Desc/Describe
Rename

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 34


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

DDL Commands:-
DDL Commands are used to create, modify and delete the structure of object
in the database. The syntax of DDL commands always includes table keyword after
the command name.
 Create
 Describe/desc
 Alter
 Drop
 Truncate
 Rename
CREATE TABLE Command:-
The CREATE TABLE statement is used to create tables to store data. It is
used to create structure of the table. Integrity constraints like primary key, unique key
& foreign key can be defined for the columns while creating table.
Syntax:
CREATE TABLE <table name> (column1 data type(size), column2
data type(size),……..);
--table name is the name of the table.
--column1, column2, …… are column names.
--data type is the data type of columns like char, date, number etc.
Ex:
SQL>CREATE TABLE emp(id number(5), name char(20), dept
char(10), sal number(10));
SQL> Table Created
DESCRIBE/DESC TABLE Command:-
DESCRIBE TABLE is used to list all the columns in the specified table or
view. It displays one row per table column containing:
 Column
 Type
 Nullable
 Primary Key
Syntax:
DESC <table name>;
EX:

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 35


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

SQL>DESC std;
ALTER TABLE Command:-
ALTER TABLE command is used to modify the structure of a table by
modifying the definition of its columns. It is used to perform following functions:
1. Add, drop, modify table/columns.
2. Add and drop constraints.
3. Enable and disable constraints.
Syntax:
ALTER TABLE table_name ADD(new column data type(size));
ALTER TABLE table_name MODIFY(new column data type(size));
Syntax to add a column:
ALTER TABLE table_name ADD column_name data type(size);
Ex:
SQL> ALTER TABLE emp ADD experience number(3);
SQL> Table altered
Syntax to drop a column:
ALTER TABLE table_name DROP column_name;
Ex:
SQL> ALTER TABLE emp DROP location;

Syntax to modify a column:


ALTER TABLE table_name MODIFY column_name data type(size);
Ex:
SQL> ALTER TABLE emp MODIFY sal number(15,2);
DROP TABLE Command:-
The DROP command is used to remove an object from the database. Once a
table is dropped we cannot get it back. It is used to destroy a table structure.
Syntax:
DROP TABLE table_name;
Ex:
SQL> DROP TABLE emp;
TRUNCATE:-
The TRUNCATE command is used to delete all the rows from the table and
free the memory space.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 36


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Syntax:
TRUNCATE TABLE table_name;
Ex:
SQL> TRUNCATE TABLE emp;
Differences between DROP and TRUNCATE:-
If a table is dropped, all the relationships with other tables are not valid, the
integrity constraints are dropped. If we want to use the table again, we have to
create it again with the integrity constraints and relationships with other tables should
be established.
But if a table is truncated, the table structure remains same, so the problems of
the drop are not there in truncate.
RENAME Command:-
RENAME command is used to change the name of a table.
Syntax:
RENAME TABLE <old table name> TO <new table name>;
Ex:
SQL> RENAME TABLE emp TO employ;
SQL> Table Renamed

DML COMMANDS:
DML commands allows user to access the table and insert, modify and delete
data in the table. These commands are only used on data of the table but does not
involve with structure of the table.
The DML commands are:
 Insert
 Select
 Update
 Delete
INSERT Command:-
This command is used to enter and store the values in the database. The data
values given by the user in insert statement should match with the data type
declared for the selected column in the table. SQL insert command is implemented
in 3 methods.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 37


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Simple insert statement:-


It is used to insert a single row of value in the selected table
Syntax:
INSERT INTO <table name> values(column1 value, column2
value,……columnN value);
Ex:
SQL>INSERT INTO student values(1,’sam’,430,’Bcom’);
Partial insert statement:-
It is used to enter values for selected columns by leaving other columns.
Syntax:
INSERT INTO <table name> (column1, column3, column5) values
(column1 value, column3 value, column5 value);
Ex:
SQL>INSERT INTO student (sno, name, marks, branch) values
(1,’sam’,430,’Bcom’);
Interactive insert statement:-
It is used to enter multiple values to the selected table with various values.
Ampersand operator (&) is used to display interactive messages to accept the values
given by the user and store the values in the given field.
Syntax:
INSERT INTO <table name> values (&column1, &column2,----&column);
Ex:
SQL>INSERT INTO std values(&sno,’&sname’,’&class’);
SQL>Enter value for sno: 1
SQL>Enter value for sname: ajay
SQL>Enter value for class: Bcom
SQL>1 row inserted
SQL>/
The above command will insert 1 record and repeat the statement by using /
operator in the command.
SELECT Command:-
The SQL SELECT command is used to retrieve data from a table in the
database. A query may retrieve information from specified columns or from all
columns in the table.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 38


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Syntax:
SELECT column-list FROM table-name
[WHERE clause]
[GROUP BY clause]
[HAVING clause]
[ORDER BY clause]
--WHERE clause is used to give conditions and retrieve only selected records.
--GROUP BY clause is used to collect data from multiple records and group results
by one or more columns.
--HAVING clause is used with GROUP BY clause to filter records given by GROUP
BY clause.
--ORDER BY clause is used to sort the result set by a specified column either in
ascending or descending order.
ASELECT statement is used to display the records in multiple methods as:
 All rows and all columns
 Selected columns and all rows
 Selected rows with all columns
 Selected rows with selected columns
Ex:
SQL> SELECT * FROM std;
SQL> SELECT sno, sname, dob FROM std;
SQL> SELECT * FROM std WHERE sno=3;
UPDATE Command:-
It is used to edit or update the data based on conditions for selected record or
field. Update command is implemented with SET keyword which changes previous
values with current values.
Syntax:
UPDATE <table-name> SET column-name1=value1, column-
name2=value2,…. [WHERE condition];
Ex:
SQL> UPDATE std SET name=’akshay’ WHERE sno=3;
DELETE Command:-
DELETE command is used to delete records from the table either single
record or multiple records based on a condition using WHERE clause.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 39


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Syntax:
DELETE FROM table-name [WHERE condition];
Ex:
SQL>DELETE FROM std WHERE name=’priya’;
SQL> DELETE FROM std;
This command deletes all the rows from the table if no condition is specified.
DCL COMMANDS:
DCL commands allow database administrators to configure security access to
relational databases. Two types of DCL commands are GRANT and REVOKE. Only
database administrator or owner of database object can provide/remove privileges
on database object.
GRANT Command:-
GRANT is a command used to provide access or privileges on
database objects to users.
Syntax:
GRANT privilege-name ON object-name TO {user-name|PUBLIC|role-
name} [WITH GRANT OPTION]
--Privilege-name is access right granted to the user. Some of access
rights are ALL, EXECUTE & SELECT.
--Object-name is name of database object like TABLE, VIEW &
STORED PROC.
--User-name is name of the user to whom access right is granted.
--PUBLIC is used to grant access rights to all users
--Role-name is set of privileges grouped together
--WITH GRANT OPTION allows user to grant access rights to other
users.
EX:
SQL> GRANT SELECT ON student TO jaya;
REVOKE Command:-
REVOKE command is used to remove given privileges from selected
user of the database.
Syntax:
REVOKE [GRANT OPTION FOR] [permission] ON [object] FROM
[user] [CASCADE]

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 40


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

--GRANT OPTION FOR removes the specified user’s ability to grant specified
permission to other users.
--CASCADE revokes the specified permission from any users.
EX:
SQL> REVOKE SELECT ON student FROM jaya;
TCL COMMANDS:
TCL commands are used in transactions performed by users. The TCL
commands are COMMIT, ROLLBACk & SAVEPOINT.
COMMIT:-
A COMMIT statement commits all the changes made to the data. It
commits all changes made by SQL statements during unit of work.
EX:
SQL> COMMIT;
ROLLBACK:-
ROLLBACK is a process of undoing changes to a database. It ends a
unit of work and back out all relational database changes made by that unit of
work. Rolling back to save point enables selected changes to be undone.
A ROLLBACK is automatically performed when:
 The default activation group ends without a final COMMIT
 A failure occurs that prevents activation group to complete its
work
 A failure occurs that causes a loss of connection to an
application server.
 An activation group other than default activation group ends
abnormally.
SAVE POINT:-
The SAVE POINT statement names and marks the current point in the
processing a transaction.
 A simple rollback or commit erases all save points.
 The save point moves from its old position to current position in
the transaction.
 An implicit save point is marked before executing an INSERT,
UPDATE or DELETE statement. If the statement fails, a rollback
to the implicit save point is done.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 41


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

EX:
SQL> SAVE POINT ss1;
SQL WHERE CLAUSE:
SQL WHERE clause is used to specify a condition while getting the data from
single table or joining with multiple tables. If the given condition is satisfied then only
it returns specific value from the table. WHERE clause is used to filter the records
and fetch only necessary records. The WHERE clause is not only used in SELECT
statement but also in UPDATE, DELETE statements etc.
Syntax:
SELECT col1, col2,.….,colN FROM table-name WHERE [condition];
EX:
SQL> SELECT * FROM Emp WHERE sal>5000;
SQL NULL VALUE:
The SQL NULL is the term used to represent missing data. A field with a
NULL value is a field with no value. NULL values represent missing unknown data.
By default a table column can hold NULL values.
We have to use IS NULL and IS NOT NULL operators for retrieving NULL
content.
EX:
SQL> CREATE TABLE emp (id number(3) NOT NULL, name varchar2(30)
NOT NULL, sal number(15,2), address carchar2(30));
The NULL value can cause problems when selecting data. IS NULL or IS
NOT NULL operators are used in order to retrieve the null information to check for a
NULL value.
EX:
SQL>SELECT * FROM emp WHERE sal IS NOT NULL;
SQL>SELECT * FROM emp WHERE sal IS NULL;
GROUP BY & HAVING:
SQL GROUP BY aggregates column values into a single record value.
GROUP BY requires a list of table columns on which the calculations are performed.
EX:
SQL> SELECT address FROM emp GROUP BY address;
Address
Delhi

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 42


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Mumbai
Indore
SQL returned the values that are unique. We can also use mathematical functions
with GROUP BY like SUM().
EX:
SQL> SELCT address, SUM(sal) AS “area wise total sal” FROM emp;
Address Area wise total salary
Delhi 23000
Mumbai 8000
Indore 13000
GROUP BY clause helps the user to retrieve selected data and also perform
calculations.
The SQL HAVING clause is like a WHERE clause for aggregated data. IT is
used with conditional statements just like WHERE to filter results. Any column name
used in HAVING clause must also appear in GROUP BY clause.

EX:
SQL>SELECT address, SUM(sal) FROM emp GROUP BY address
HAVING SUM (sal)>1000;
Address Sal
Delhi 23000
Mumbai 8000
Indore 13000
SQL JOINS:
SQL Joins are used to relate information in different tables. A SQL join
condition is used in SQL WHERE clause of select, update, delete statements. It
combines records from two or more tables in a database. It combines fields from two
tables by using common values.
Joining two tables effectively creates another table which combines
information from both tables.
SQL joins can be classified into Equi join and Non Equi join.
1. SQL Equi join:
It is a simple SQL join condition which uses equal sign as comparison
operator. An equi-join is further classified into two categories:

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 43


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

a) SQL Inner Join


b) SQL Outer Join
a) SQL Inner Join:-
Returns all the rows returned by the SQL query satisfy the SQL join
condition that is specified.
b) SQL Outer Join:-
It returns all rows from both tables which satisfy the join condition along
with rows which do not satisfy the join condition from one of the tables.
SQL Self Join:-
A self join is a type of SQL join which is used to join a table to itself,
particularly when the table has a foreign key that references its own primary
key.
2. SQL Non Equi Join:
A Non Equi Join is a SQL join whose condition is established using all
comparison operators except equal operator like >, <, >=, <=.
Syntax for joining two tables:
SELECT col1, col2,……FROM table-name1, table-name2 WHERE
table-name1.col2=table-name2.col1;
If a SQL join condition is invalid the join operation will result in a Cartesian
product. The Cartesian product returns a number of rows equal to the product
of all rows in all tables being joined.
CROSS JOIN:
Cross join returns the Cartesian product of rows from tables in the join. It will
give rows which combine each row from the first table with each row from the second
table.
EX:
Explicit cross join
SQL> SELECT * FROM emp CROSS JOIN dept;
Implicit cross join
SQL> SELECT * FROM emp,dept;
INNER JOIN:
Inner join is the most common join operation used in applications. It creates a
new result table by combining column values of two tables based on the join
predicate.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 44


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

SQL specifies two different syntaxes to express joins: explicit join notation and
implicit join notation.
The explicit join notation uses the JOIN keyword to specify the table to join
and ON keyword to specify predicates for the join.
Ex:
SQL>SELECT * FROM emp INNER JOIN dept ON emp.Did=dept.Did;
The implicit join notation simply lists the tables for joining in the FROM clause
of the SELECT statement using commas to separate them.
Ex:
SQL>SELECT * FROM emp, dept WHERE emp.Did=dept.Did;
The inner joins are further classified into equi joins, natural joins or as cross joins.
--Equi Join:-
It is a comparator based join that uses only equality comparisons in the
join predicate.
Ex:
SQL>SELECT * FROM emp JOIN dept ON emp.Did=dept.Did;
Or
SQL>SELECT * FROM emp, dept WHERE emp.Did=dept.Did;
If the columns in an equi-join have same name, SQL provides a short hand
notation for expressing equi joins by the construct USING.
SQL>SELECT * FROM emp INNER JOIN dept USING(Did);
--Natural Join:-
A natural join is a type of equi join where the join predicate arises
implicitly by comparing all columns in both tables that have same column
names in the joined tables. The resulting table contains only one column for
each pair of equally named columns.
Ex:
SQL>SELECT * FROM emp NATURAL JOIN dept;
OUTER JOIN:
An outer join does not require each record in the two joined tables to have a
matching record. The joined table gets each record even if no other matching record
exists.
Outer joins are classified into left outer joins, right outer joins and full outer
joins.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 45


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

--Left outer join:-


The result of left outer join or left join for table A and B always contains
all records of the left table A even if the join condition does not find any
matching record in the right table B.
A left outer join returns all the values from an inner join plus all values
in the left table that do not match to the right table.
Ex:
SQL>SELECT * FROM emp LEFT OUTER JOIN dept ON
emp.Did=dept.Did;
--Right outer join:-
A right outer join or right join contains all records of the right table even
if the join condition does not find any matching record in left table.
A right outer join returns all values from the right table and matched
values from the left table.
Ex:
SQL>SELECT * FROM emp RIGHT OUTER JOIN dept ON
emp.Did=dept.Did;
--Full outer join:-
A full outer join combines the effect of applying both left and right outer
joins. When records in the joined tables do not match, the result set will have
NULL values for every column of the table. For those records that do not
match, a single row will be produced in the result set.
Ex:
SQL>SELECT * FROM emp FULL OUTER JOIN dept ON
emp.Did=dept.Did;
SQL VIEWS:
To reduce a redundant data to the minimum, Oracle allows the creation of an
object called a View. A view is mapped to a SELECT statement. The SELECT
clause consists of a subset of columns of the tables.
A view is a virtual table through which a selective portion of data from one or
more tables can be seen. Views do not contain data of their own. They are used to
restrict access to the database or to hide data complexity. A view is stored as a
SELECT statement in the database.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 46


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

SQL views are data objects and like SQL tables they can be queried, updated
and dropped. A SQL VIEW is a virtual table containing columns and rows except that
the data contained inside a view is generated dynamically from SQL tables and does
not exist inside the view itself.
A view used only to look table data is called read-only view. A view used to
look and implement insert, update and delete statements is called updatable view.
Reasons to create a view:
 When data security is required
 When data redundancy is to be kept minimum.
Creating a view:
CREATE VIEW view-name AS SELECT column-list FROM table-name
[WHERE condition];
The SELECT statement is used to define the columns and rows to display in
the view.
Ex:
SQL>CREATE VIEW vemp AS SELECT eid, ename FROM emp;
Updating a view:
The definition of the view created in SQL can be modified without
dropping it by using following syntax:
CREATE OR REPLACE VIEW view-name AS SELECT column=list
FROM table-name WHERE condition;
Ex:
SQL>CREATE OR REPLACE VIEW vemp AS SELECt eid, ename, sal
WHERE sal>5000 FROM emp;
Updatable and Read-Only VIEWs:
Views are either updatable or read-only but not both. INSERT,UPDATE and
DELETE operations are allowed on updatable views and base tables but not allowed
on read-only views.
An updatable view is one that can have each of its rows associated with
exactly one row in base table. When a view is changed, the changes pass through
the view to base table.
Updatable views in standard SQL are defined only for queries that meet these
criteria:

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 47


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

1. They are built on only one table.


2. No GROUP BY clause.
3. No HAVING clause.
4. No aggregate functions.
5. No calculated columns.
6. No UNION, INTERSECT or EXCEPT.
7. NO SELECT DISTINCT clause.
Each row in the view maps back to one and only one row in the base table.
Dropping Views:
Views like tables can be dropped from the schema. The SQL syntax for the
statement is:
DROP VIEW <table name list>;
When a view is dropped, the engine usually removes the appropriate row from
the schema information tables. Dropping a base table could cause the same problem
when the view was accessed. But the primary key/foreign key dependencies among
base tables will prevent dropping some base tables.
NESTED QUERIES:
A nested query is a query that is nested inside another query. The inner query
is always executed first by the RDBMS. A nested query is also known as a sub query
or an inner query.
Characteristics of Nested query:
 A nested query is a query inside a query.
 It can be expressed inside parenthesis.
 The first query in the SQL statement is known as outer query.
 The query inside the SQL statement is known as inner query.
 The output of an inner query is used as the input for the outer query.
Types of Nested queries:
The following are the types of nested queries:
1. WHERE Sub queries:
The sub query that is used in inner SELECT sub query on the right side
of a WHERE condition is known as WHERE sub query.
EX:
SQL>SELECT P_code, P_price FROM PRODUCT WHERE
P_price>=(SELECT Avg(P_price) FROM PRODUCT);

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 48


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

2. IN Sub queries:
When we want to compare a single attribute with a list of values, we
use IN operator/IN sub query.
The following example lists all customers who have purchased hammers,
saws or saw blades.
EX:
SQL>SELECT C-code, C_name FROM CUST JOIN PRODUCT WHERE
P_code IN (SELECT P_code FROM PRODUCT WHERE P-desc LIKE
‘%hammer%’ OR P-desc LIKE ‘%saw%’);
3. HAVING Sub queries:
A sub query with a HAVING clause is known as a HAVING sub query.
Generally, HAVING clause is used to filter the output of a GROUP BY query.
EX:
SELECT P_code, SUM(P-units) FROM PRODUCT GROUPBY P_code
HAVING SUM(P_units)>(SELECT AVG(P_units) FROM PRODUCT);

CORRELATED Sub Queries:


A Correlated sub query is a sub query that executes for each row in the outer
query. This is similar to a nested loop in a programming language.
For Example:
FOR X=1 TO 2
FOR Y=1 TO 3
PRINT “X=X”, “Y=Y”
END
END
will yield the output:
X=1 Y=1
X=1 Y=2
X=1 Y=3
X=2 Y=1
X=2 Y=2
X=2 Y=3

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 49


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

For a correlated sub query, the RDBMS works as follows;


1) It initiates the outer query.
2) For each row of the outer query, it executes the inner query.
The query is called a correlated sub query because the inner query is related
to the outer query by referencing a column of the outer sub query.
EX:
SQL>SELECT P-code, P-units FROM PRODUCT, LINE WHERE
P_units>(SELECT AVG(P_units) FROM PRODUCT WHERE
PRODUCT>P_code=LINE.P_code);

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 50


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

UNIT-4
TRANSACTIONS AND CONCURRENCY MANAGEMENT

Transaction:
A transaction is any action that reads from (and/or) writes to a database. A
transaction is a logical unit of work that must be entirely completed successfully or
entirely aborted (cancelled), no intermediate states are accepted.
A successful transaction changes the database from one consistent state to
another.
Transaction States:
Each and every transaction has following 5 states:
1. Active
2. Partially committed
3. Committed
4. Failed
5. Aborted

1. Active state:
This is the first state of transaction and here transaction is being
executed.
2. Partially committed state:
This is also an execution phase where last step in the transaction is
executed. But data is not saved in the database.
3. Committed state:
In this state, all the transactions are permanently saved to the
database. This step is the last step of a transaction if it executes without fail.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 51


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

4. Failed state:
If a transaction cannot proceed to the execution state because of
failure of system or database, then the transaction is said to be in failed state.
5. Aborted state:
If a transaction is failed to execute, then the database recovery system
brings the database to consistent state by aborting or rolling back the
transaction. If the transaction fails in the middle, all the executed transactions
are rolled back to consistent state before executing the transaction. Once the
transaction is aborted it is either restarted or killed by the DBMS.

Transaction Properties (ACID Properties):


Each transaction must have Atomicity, Consistency, Isolation and Durability.
These properties sometimes referred as ACID test. The following is a brief
description of these properties:
Atomicity:
Atomicity requires that all operations of a transaction be completed if not the
transaction is aborted. If a transaction T1 has four SQL requests then all 4 requests
must be successfully completed otherwise the entire transaction is aborted.
Consistency:
Consistency indicates the database should be in consistent state. A
transaction takes database from one consistent state to another consistent state
when a transaction is completed.
Isolation:
Isolation means that the data used during the execution of a transaction
cannot be used by a second transaction until the first one is completed.
If a transaction T1 is being executed and it is using the data item ‘X’ then the
data item cannot be accessed by any other transactions (T2, T3, - - - , Tn) until T1
is completed. This property is particularly used in Multi-user database
environment.
Durability:
Durability ensures that once transaction changes are done (committed) they
cannot be undone or lost even in the event of system failure.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 52


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Concurrent Transactions:
When many transactions take place at the same time, they are called
Concurrent transactions. Managing the execution of concurrent transactions is called
concurrency control.
Serializable Schedules:
A schedule is a process of grouping the transactions into one and executing
them in a predefined order. A schedule is required in a database because when
some transactions execute in parallel, they may affect the result of the transaction –
means if one transaction is updating the values which the other transaction is
accessing, then the order of these two transactions will change the result of second
transaction.
A schedule is called serial schedule, if the transactions in the schedule are
defined to execute one after the other.
Serializability ensures that the schedule for the concurrent execution of the
transactions give consistent results. This property is important in multi-user and
distributed database system.
Locking Protocol:
A locking protocol is a set of rules that describes how the database entities
can be accessed.
Concurrency Control:
When there are multiple transactions executing at the same time on same
data, it may affect the result of the transaction. Hence it is necessary to maintain
the order of execution of those transactions. In addition, it should not alter the
ACID property of a transaction.
In order to maintain the concurrent access of transactions, two protocols are
introduced.

 Lock Based Protocol: - Lock is in other words called as access. In this type
of protocol any transaction will not be processed until the transaction gets the
lock on the record. That means any transaction will not retrieve or insert or
update or delete the data unless it gets the access to that particular data.

These locks are broadly classified as Binary locks and shared / exclusive locks.

Binary lock: In this, data can either be locked or unlocked. It will have only these
two states. It can be locked for retrieve or insert or update or delete the data or
unlocked for not using the data.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 53


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Shared / Exclusive lock: In this technique the data is said to be exclusively locked if
for insert / update /delete. When it is exclusively locked no other transaction can read
or write the data. When a data is read from the database, then its lock is shared i.e.;
the data can be read by other transaction too but it cannot be changed while
retrieving the data.

Lock based protocols are of 4 types

Simplistic Lock Protocol: -As the name suggests it is the simplest way of locking
the data during the transaction. This protocol allows all the transaction to get the lock
on the data before insert / update /delete on it. After completing the transaction, it will
unlock the data.

Pre-claiming Protocol: - In this protocol, it evaluates the transaction to list all the
data items on which transaction needs lock. It then requests DBMS for the lock on all
those data items before the transaction begins. If DBMS gives the lock on all the
data, then this protocol allows the transaction to begin. Once the transaction is
complete, it releases all the locks. If all locks are given by DBMS, then it reverts the
transactions and waits for the lock.

For example, if we have to calculate total marks of 3 subjects, then this protocol will
evaluate the transaction and list the locks on subject1 marks, subject2 marks and
then subject3 marks. Once it gets all the locks, it will start the transaction.

Two Phase Locking Protocol (2PL): - In this type of protocol, as the transaction
begins to execute, it starts requesting for the locks that it needs. It goes on
requesting for the locks as and when it is needed. Hence it has a growing phase of
locks. At one stage it will have all the locks. Once the transaction is complete it goes
on releasing the locks. Hence it will have descending phase of locks. Thus this
protocol has two phases – growing phase of locks and shrinking phase of locks.

For example, if we have to calculate total marks of 3 subjects, then this protocol will
go on asking for the locks on subject1 marks, subject2 marks and then subject3
marks. As and when it gets the locks on the subject marks it reads the marks. It does

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 54


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

not wait till all the locks are received. Then it will have total calculation. Once it is
complete it release the lock on subject3 marks, subject2 marks and subject1 marks.

In this protocol, if we need to have exclusive lock on any data for writing, then we
have to first get the shared lock for reading. Then we have to request / modify the
lock to exclusive lock.

Strict Two Phase Locking (Strict 2PL): - This protocol is similar to 2PL in the first
phase. Once it receives the lock on the data, it completes the transaction. Here it
does not release the locks as it is used and no more required. It waits till whole
transaction to complete and commit, then it releases all the locks at a time. This
protocol hence does not have shrinking phase of lock release.

In the example of calculating total marks of 3 subjects, locks are achieved at


growing phase of the transaction and once it receives all the locks, it executes the
transaction. Once the transaction is fully complete, it releases all the locks together.
 Time Stamp Based Protocol: -
In lock based protocol, it acquires locks at the time of execution. But in
this method, as soon as a transaction is created it assigns the order of the
transaction. The order of the transaction is nothing but the ascending order of
the transaction creation. The priority for older transaction is given to execute
first. This protocol uses system time or logical counter to determine the time
stamp of the transaction.
Suppose there are two transactions T1 and T2. Suppose T1 has
entered the system at time 0005 and T2 has entered the system at 0008 clock
time. Priority will be given to T1 to execute first as it is entered the system
first.
In addition to the timestamp of a transaction, this protocol also
maintains the timestamp of last ‘read’ and ‘write’ operation on a data. Based
on the timestamp of transaction and the data which it is accessing a
timestamp ordering protocol is defined.
According to this protocol:
If a transaction T is a read transaction on data X then

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 55


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

This algorithm states that if there is an active write operation on data X when
a transaction T is requesting for X, then reject the transaction T. If the transaction T
is started as soon as write is complete or no going write operation on X, then
execute T.

For example, if there is an update on marks1 on MARKS table and meanwhile


there is a request to read marks1, then do not perform read marks1. This is because
there is an update being happening on marks1. If there was an update on marks1
which is executed long back or it is complete just now and there is a request to read
marks1, then system will allow reading marks1.

 If a transaction T is a write transaction on data X then

This algorithm describes about write operation. If there is an active read or write
on data X, and at the same time if the transaction T is requesting for X, then the
transaction is rejected. If there is no active read / write operation on X, then execute
the transaction.

Suppose T1 is reading marks1 from MARKS table. Meanwhile transaction T2


begins and tries to update marks1 in MARKS. Then the transaction T2 is rejected
and rolled back.

DEADLOCK:
Dead lock occurs when two transactions wait for each other to unlock data.
Dead locks are possible only when one of the transactions wants to obtain an
exclusive lock on a data item. Dead lock condition does not exist among shared
locks.

Above diagram shows how two transactions are waiting for each other and never
completes.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 56


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

If a deadlock occurs in the database, then the transactions have to be


restarted or rolled back. In above case, if the second transaction starts after T1
fetches Tom’s address, then there would not have been a deadlock situation. It has
occurred because both the transactions have started simultaneously.

Deadlock avoidance

It is always better to avoid deadlock in a system rather than aborting or


restarting the transaction. This is waste of time and resource. Wait-for-graph is one
of the methods for detecting the deadlock situation. But this method is suitable for
smaller database. For large database deadlock prevention method may help.

Wait-For-Graph

In this method a graph is drawn based on the transaction and their lock on the
resource. If the graph created has a closed loop, then there is a deadlock. In DBMS
maintains this graph for all the transactions waiting for the resources and checks if
there is a loop.
Suppose T1 and T2 are two transactions. Suppose T1 is requesting for a
resource R which is held by T2. In this case, wait for graph draws an arrow from T1
to T2. If T2 releases the resource R, then this arrow is deleted.

Deadlock Prevention
The DBMS verifies each transaction and sees if there can be deadlock
situation upon execution of the transaction. If it finds everything is fine, then allows
the transaction to execute. If it finds that there can be a deadlock, it never allows the
transaction to execute.
DBMS basically checks for the timestamp at which a transaction has been
initiated and orders the transactions based on it. If there are any transactions at
same time period with requesting each other resource, then it stops those
transactions before executing it. In above case, DBMS will never allow the
transaction to execute simultaneously. This method is suitable for large system.

There are different methods to prevent the deadlock

Wait-Die Scheme
In this method, if a transaction request for the resource which is already
locked by other transaction, then the DBMS checks for the timestamp of both the
transaction and allows older transaction to wait until the resource is available for
execution.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 57


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Suppose T1 and T2 be two transactions and let timestamp of any transaction T be


TS (T). If there is a lock on T2 by some other transaction and T1 is requesting for T2
resources, then DBMS performs following actions:

 Checks if TS (T1) <TS (T2) – if T1 is the older transaction and T2 has held
some resource, then it allows T1 to wait until resource is available for
execution. That means if a younger transaction has locked some resource
and older transaction is waiting for it, then older transaction is allowed wait for
it till it is available.
 If T1 is older transaction and has held some resource with it and if T2 is
waiting for it, then T2 is killed and restarted latter with random delay but with
the same timestamp. i.e.; if the older transaction has held some resource and
younger transaction waits for the resource, then younger transaction is killed
and restarted with very minute delay with same timestamp.

In our above example of address update, if T1 is older transaction, then it


waits till the address of Tom is available. Meanwhile it kills T2 and makes Address
available for T1. Soon T2 will be restarted (hence there will be delay - start Kill
restart) and it continues with its transaction. By this time T1 would have been
completed and T2 will not have to wait. Although all these transactions look like
taking time, all this happens in fraction of seconds and we cannot really observe the
start/ delay/ restart / End.

Wound Wait Scheme


In this method, if an older transaction requests for a resource held by younger
transaction, then older transaction forces younger transaction to kill the transaction
and release the resource. The younger transaction is restarted with minute delay but
with same timestamp. If the younger transaction is requesting a resource which is
held by older one, then younger transaction is asked to wait till older releases it.

OPTIMISTIC CONCURRENCY CONTROL:


Optimistic concurrency control was first proposed by H.T. Kung and John T.
Robinson. The optimistic method of concurrency control is based on the assumption
that conflicts of database operations are rare and that it is better to let transactions
run to completion and only check for conflicts before they commit.
An optimistic concurrency control method is also known as validation or
certification methods. No checking is done while the transaction is executing. The
optimistic method does not require locking or time stamping techniques. Instead, a
transaction is executed without restrictions until it is committed.
In optimistic methods, each transaction moves through the following phases:
a) Read phase.
b) Validation or certification phase.
c) Write phase.

a. Read phase :
In a Read phase, the updates are prepared using private (or local) copies (or
versions) of the granule. In this phase, the transaction reads values of committed
data from the database, executes the needed computations, and makes the updates

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 58


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

to a private copy of the database values. All update operations of the transaction are
recorded in a temporary update file, which is not accessed by the remaining
transactions.
It is conventional to allocate a timestamp to each transaction at the end of its
Read to determine the set of transactions that must be examined by the validation
procedure. These set of transactions are those who have finished their Read phases
since the start of the transaction being verified

b. Validation or certification phase :


In a validation (or certification) phase, the transaction is validated to assure that
the changes made will not affect the integrity and consistency of the database.
If the validation test is positive, the transaction goes to the write phase. If the
validation test is negative, the transaction is restarted, and the changes are
discarded.
Thus, in this phase the list of granules is checked for conflicts. If conflicts are
detected in this phase, the transaction is aborted and restarted. The validation
algorithm must check that the transaction has :

 Seen all modifications of transactions committed after it starts.


 Not read granules updated by a transaction committed after its start.

c. Write phase :
In a Write phase, the changes are permanently applied to the database and
the updated granules are made public. Otherwise, the updates are discarded and the
transaction is restarted. This phase is only for the Read-Write transactions and not
for Read-only transactions.
Advantages of Optimistic Methods for Concurrency Control:
i. This technique is very efficient when conflicts are rare. The occasional
conflicts result in the transaction roll back.
ii. The rollback involves only the local copy of data, the database is not involved
and thus there will not be any cascading rollbacks.
Problems of Optimistic Methods for Concurrency Control:
i. Conflicts are expensive to deal with, since the conflicting transaction must be
rolled back.
ii. Longer transactions are more likely to have conflicts and may be repeatedly
rolled back because of conflicts with short transactions.
Applications of Optimistic Methods for Concurrency Control :
i. Only suitable for environments where there are few conflicts and no long
transactions.
ii. Acceptable for mostly Read or Query database systems that require very few
update transactions

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 59


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

DATABASE BACKUP AND RECOVERY:


The DBA must ensure that the data in the database can be fully recovered in
case of physical data loss or loss of database integrity. Data loss can be partial or
total. A partial loss is caused by a physical loss of part of the database or when part
of the database has lost its integrity. A total loss means that the database continues
to exist but its integrity is entirely lost or the entire database is physically lost.
The backup and recovery measures must include at least:
--Periodic data and applications backups:-
Some DBMSs include tools to ensure backup and recovery of the data in the
database. The DBA must use those tools to make backup and recovery tasks
automatic. A full backup also known as database dump is a copy of the entire
database. An incremental backup gives a backup of all data since the last backup
date. A concurrent backup takes place while the user is working on the database.
--Proper backup identification:-
Backups must be clearly identified through detailed descriptions and date
information thus making the DBA to ensure that the correct backups are used to
recover the database. Enterprise backup solutions use a layered backup approach in
which the data is first backed up to fast disk media for intermediate storage and fast
restoration.
--Convenient and safe backup storage:-
There must be multiple backups of the same data and each backup copy
must be stored in a different location. The storage locations must include sites inside
and outside the organization. The DBA must establish a policy to respond to two
questions: where are the backups to be stored? And how long are backups to be
stored?
--Physical protection of both hardware and software:-
Protection might include the use of closed installations with restricted access
as well as preparation of computer sites to provide air conditioning, backup power
and fire protection.
--Personal access control to the software of a database installation:-
Multilevel passwords, privileges, hardware and software challenge/response
tokens can be used to properly identify authorized users of resources.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 60


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

--Insurance coverage for the data in the database:-


The DBA must secure an insurance policy to provide financial protection in
the event of database failure.
Sources of Failure:
1. System errors:-
The system has entered an undesirable state such as deadlock which
prevents the program from continuing with normal processing. This type of
failure may or may not result in corruption of data files.
2. Hardware failures:-
Two most common types of hardware failures are disk failure and loss
of transmission capability over a transmission link. Disk failure results from the
disk read/write head coming in physical contact with the disk surface.

3. Logical errors:-
Bad data or missing data are common conditions that may stop the
program continuing with normal execution.
Recovery Procedures:
To maintain data integrity, a transaction must be in one of the following two
states:
1. Aborted:-
A transaction may not always complete its process successfully. To
make sure the incomplete transaction will not affect the consistent state of the
database, such transactions must be aborted.
2. Committed:-
A transaction that successfully completes its processing is said to be
committed. A committed transaction always leaves the database in a new
consistent state. The log plays a key role in failure recovery.
Database Backups:
Database backups can be either physical or logical.
Physical backups are primary concern in backup and recovery strategy which
are copies of physical database files.
Logical backups contain logical data such as tables and stored procedures.
Logical backups can supplement physical backups.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 61


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Physical backups have large granularity and limited transportability but are
very fast. Logical backups have fine granularity and complete transportability but are
slower than physical backups.
DATABASE SECURITY:
Unauthorized access to the database includes the following:
 Theft of information
 Unauthorized modification of data
 Un authorized destruction of data
Database security methods focus on preventing unauthorized users from
accessing the database.
Authentication:-
Database access usually requires user authentication and authorization. For
user authentication, the first level of security establishes that the person seeking
system entry is an authorized user. His or her identity may be established by
o Something the user knows such as log-on number and password
o Something the user possesses such as a plastic ID card
o A physical representation of the user such as finger print or voice print.
Authorization allows the database users to access certain part of database. The
process of verifying the identity of a user is called as authentication.
--Password Authentication:-
In this scheme, the user is asked to enter the user name and password to log
into the database. DBMS then verifies the combination of user name and password
to authenticate the user and allows him the access to the database if he is an
authorized user otherwise access is denied.
--Access Control:-
Most database users need only a small portion of database. Allowing them
access to whole database is undesirable. Thus an organization should develop
effective security policy to enable a group of users to access only a required portion
of the database. Once the security policy is developed, it should be enforced to
achieve the level of security required.
Authorization and Views:-
It is used to grant privileges to users which help them to access certain
portion of the database. Each user is allowed to perform only necessary operation on
the database that is required to perform their function. The person who is
responsible for granting privileges to database users is called authorizer.
The authorization information is maintained in a table called access matrix.
The columns of access matrix represent objects and rows represent subjects. Here
object is any part of the database that needs to be protected from unauthorized
access. Subject is an active user or account who operates on various objects in the
database.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 62


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

A view is a means of providing user with a personalized model of the


database. It is also useful way of limiting a user’s access to various portions of the
database. Views can be represented by executing selects, projections and joins on
existing relations.
By creating different views for different classes of users, a high degree of
access control is automatically obtained. A combination of relational-level security
and view-level security can be used to limit a user’s access to the data that user
needs.
--Types of View Access:-
Different types of access authorization may be allowed for a particular view as
follows:
o Read authorization
o Insert authorization
o Update authorization
o Delete authorization
Encryption:
Encryption is a process of maintaining data security in an insecure
environment like transmitting data over an insecure communication link. It involves
applying an encryption algorithm to the data or plain text using a pre specified
encryption key. The algorithm produces encrypted version of the plain text as the
output.
Encrypted data cannot be read by anyone unless they know the encryption
method. Some methods are easy to decrypt, others are very difficult to decrypt and
provides high level protection.
--Simple substitution method:-
This method shifts each letter to its immediate successor in the
alphabet. Better encryption schemes use an encryption key.
--Poly-alphabetic substitution method:-
Align the key below the plain text repeating it as many times as
necessary for the plain text to be completely covered.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 63


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

UNIT-5
DISTRIBUTED AND CLIENT SERVER DATABASES

DISRIBUTED DATABASES:

A distributed database is an integrated database which is built on top of a


computer network rather than on a single computer. The data within the database is
stored at different sites of a computer network an application programs of computers
access data at different sites.

A Distributed Database Management System (DDBMS) is defined as the


software that handles the management of distributed database.

Types of DDBMS:

DDBMS are basically divided into 2 major types:


Homogeneous distributed database:-
o All sites have identical software
o Agree to cooperate in processing user requests
o Appears to user as a single system
Heterogeneous distributed database:-
o Different sites may use different schemas and software
o Difference in schema is a major problem for query processing
o Difference in software is a major problem for transaction processing
o Provides only limited facilities for cooperation in transaction processing
Distributed Database:
A logically inter-related collection of shared data, physically distributed over a
computer network.
Distributed DBMS (DDBMS):
It is a software system that permits the management of the distributed
database and makes the distribution transparent to users.
Characteristics of DDBMS:
A DDBMS control the storage and processing of logically related data over
inter connected computer systems in which both data and processing functions are
distributed among several sites. The following are the characteristics of DDBMS:

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 64


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

o Application interface to interact with the end user, application programs


and other DBMSs.
o Validation to analyze data requests for syntax correctness.
o Query optimization to find best access strategy.
o Mapping to determine the data location of local and remote fragments.
o I/O interface to read or write data from or to permanent local storage.
o Security to provide data privacy at both local and remote databases.
o Backup and recovery to ensure the availability and recoverability of the
database in case of failure.
o Database administration features for the database administrator.
o Concurrency control to manage simultaneous data access.
o Transaction management to ensure that data moves from one
consistent state to another.
Advantages of DDBMS:
1. Data are located near greatest demand site:
The data in a distributed database system are dispersed to match
business requirements which reduce the cost of data access.
2. Faster data access:
End users work with only a locally stored subset of company’s data.
3. Faster data processing:
A distributed database system spreads out the systems workload by
processing data at several sites.
4. Growth facilitation:
New sites can be added to the network without affecting the operations
of other sites.
5. Improved communications:
Because local sites are smaller and located closer to customers, they
have better communication among departments, customers and company
staff.
6. Reduced operating costs:
It is more cost-effective to add work station to a network than to update
a mainframe system.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 65


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

7. User friendly interface:


The Graphical User Interface (GUI) simplifies training and use for end
users.
8. Less danger of a single-point failure:
When one of the computers fails, the work load is picked up by other
work stations.
9. Processor independence:
An end user’s request is processed by any processor at the data
location.
Disadvantages of DDBMS:
1. Complexity of management & control:
Applications must recognize data location and they must be able to
combine data from various sites.
2. Technological difficulty:
Data integrity, transaction management, concurrency control, security,
backup, recovery, query optimization must be addressed and resolved.
3. Security:
The responsibility of data management will be shared by different
people at several sites.
4. Lack of standards:
There are no standard communication protocols at database level.
5. Increased storage and infrastructure requirements:
Multiple copies of data are required at different sites which require
additional disk storage space.
6. Increased training cost:
Training costs are generally higher in a distributed model.
7. Costs:
Distributed databases require duplicated infrastructure to operate.
Need for distributed databases:
A distributed database is not entirely stored in one central location but is
distributed among a network of locations that are geographically separated and
connected by communication links. Each location has its own database and is able
to access data maintained at other locations.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 66


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

The reasons for development and use of distributed database systems


include:
1. Organizations have branches or divisions in different locations. During
business operations, transactions are processed against local
database conveniently. At the end of daily operations, summary results
are transmitted to corporate headquarters where a wide database is
maintained.
2. Allowing each site to store and maintain its own database. This allows
immediate and efficient access to data that are used more frequently.
3. Distributed databases can upgrade reliability. If one site’s computer
fails or if a communication link goes down, the rest of the network can
continue functioning.
4. Allowing local control over the data used most frequently at a site can
improve user satisfaction with the database system.

STRUCRURE OF DISTRIBUTED DATABASE:


The design of a distributed database system is a complex task. We should be
very careful while considering the objectives and strategies to be served by the
design and parallel decisions must be made as how data is to be distributed among
various network sites.
Strategies and Objectives:
Some of the strategies and objectives that are common to most implementations of
distributed database systems are as follows:
--Location Transparency:-
Location transparency enables a user to access data without knowing
the site at which the data reside.
--Replication Transparency:-
Replication transparency means that when more than one copy of data
exists, one copy must be chosen when retrieving data and all copies must be
updated when changes are made.
--Configuration Independence:-
Configuration independence enables the organization to add or replace
hardware without changing the existing software components of DDBMS.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 67


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

--Non-homogeneous DBMSs:-
It is sometimes desirable to integrate databases maintained by different
DBMSs on different computers. One approach of integrating these databases
is to provide a single user interface that can be used to access the data
maintained by the non homogeneous DBMSs.
Data Replication:
Data replication refers to the storage of data copies at multiple sites served by
a computer network. Data replication is the frequent electronic copying data from a
database in one computer or server to a database in another so that all users share
the same level of information.
Replicated data is subject to mutual consistency rule. The mutual consistency
rule requires that all copies of data fragments must be identical.
Advantages of Replication:-
 Availability
 Parallelism
 Reduced data transfer
Disadvantages of Replication:-
 Increased cost of updates
 Increased complexity of concurrency control
Three replication scenarios:-
o A fully replicated database stores multiple copies of each database fragment
at multiple sites.
o A partially replicated database stores multiple copies of some database
fragments at multiple sites.
o An un replicated database stores each database fragment at a single site.
Database replication can be done in at least 3 different ways:-
--Snapshot replication:
Data on one server is simply copied to another server or to another
database on the same server.
--Merging replication:
Data from two or more databases is combined into a single database.
--Transactional replication:
Users receive full initial copies of the database and then receive
periodic updates as data changes.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 68


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Database Partitioning:
A partition is a division of a logical database or its constituting elements into
distinct independent parts. Database partitioning is normally done for manageability,
performance or availability reasons. Each partition is spread over multiple nodes and
users at the node can perform local transactions on the partitions.
Efficiency is obtained by the strategy that implements a partitioned database.
With this approach, the database is distributed such that there is no overlapping or
replication of data maintained at various locations.
Reliability is also affected, since a failure of one computer system means that
the data which is stored at that location is not available to the users anywhere in the
system.
A partitioned database is treated as a series of independently operated
database systems with remote access capability.
Data Fragmentation:
Data fragmentation allows to break a single object into two or more segments
or fragments. Each fragment can be stored at any site over a computer network.
Fragmentation aims to improve:
 Reliability
 Performance
 Balanced storage capacity and costs
 Communication costs
 Security
The following information is used to decide fragmentation:
Quantitative information:
Frequency of queries, site, where query is run and selectivity of queries
etc.
Qualitative information:
Types of access of data, read/write etc.
There are 3 types of data fragmentation strategies:
 Horizontal fragmentation:-
It refers to the division of a relation into subsets (fragments) of tuples.
Each fragment is stored at a different node and each fragment has unique
rows.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 69


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

 Vertical fragmentation:-
It refers to the division of a relation into subsets (fragments) of attributes.
Each fragment is stored at a different node and each fragment has unique
columns.
 Mixed fragmentation:-
It refers to a combination of horizontal and vertical strategies. A table
may be divided into several horizontal subsets (rows) each one having a
subset of attributes (columns).
Advantages of Fragmentation:
Horizontal:
o Allows parallel processing on fragments of a relation.
o Allows a relation to be split so that tuples are located where they are most
frequently accessed.
Vertical:
o Allows tuple to be split so that each part of tuple is stored where it is most
frequently accessed.
o Tuple-id attribute allows efficient joining of vertical fragments.
Vertical and horizontal fragmentation can be combined:
o Fragments may be successively fragmented to an arbitrary depth.
Replication and fragmentation can be combined:
o Relation is partitioned into several fragments. System maintains several
identical replicas of each such fragment.
Data Integrity:
As the data is distributed, the transaction activities may take place at a
number of sites and it can be difficult to maintain a time ordering among actions.
When two or more transactions are executing at the same time and both
require access to the same data in order to complete their processing is a problem.
Most concurrency control algorithms for distributed database systems use
some form of check to see that the result of a transaction is the same as if its actions
were executed serially.
To implement concurrency control, the following must be known:
1. The type of scheduling algorithm used
2. The location of scheduler
3. How replicated data is controlled

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 70


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

When transactions are performed sequentially, all the actions are performed
and then all the actions of next transaction are executed. There is no concurrency
and this is called a serial execution.
Some of the principal methods of maintaining data integrity in a distributed
database system are Two phase commit protocol, Distributed locking and Time
stamping.
Two Phase Commit Protocol (2PC):
Under 2PC, a single transaction can update many different databases or
resources and these resources may be distributed across networks and have
independent availability and failure modes.
 Commit protocols are used to ensure atomicity across sites.
o A transaction which executes at multiple sites must either be
committed at all the sites or aborted at all the sites.
o Not acceptable to have a transaction committed at one site and
aborted at another
 The two phase commit protocol is widely used
 The three phase commit protocol (3PC) is more complicated and more
expensive but avoids some drawbacks of two-phase commit protocol
Two-phase commit protocol:-
 Assumes fail-stop model – failed sites simply stop working and do not
cause any other harm such as sending incorrect messages to other sites.
 Execution of the protocol is initiated by the coordinator after the last step of
the transaction.
 The protocol involves all local sites at which the transaction is executed
 Let T be a transaction initiated at site Si and let the transaction coordinator
at Si be Ci.
Implementation Process:-
Phase 1: The coordinator gets the participants ready to write the results into
database.
Phase 2: Everybody writes the results into database
--Coordinator: The process at the site where the transaction originates
and which controls the execution.
--Participant: The process at the other sites that participate in executing
the transaction.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 71


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Global commit rule:


--The coordinator aborts iff at least one participant votes to abort.
--The coordinator commits iff all the participants vote to commit.
Phase 1: obtaining a Decision
 Coordinator asks all participants to prepare to commit transaction Ti.
o Ci adds the records <prepare T> to the log and forces log to stable
storage
o Sends <prepare T> messages to all sites at which T executed.
 Upon receiving message, transaction manager at site determines if it can
commit the transaction
o If not, add a record <no T> to the log and send <abort T> message to
Ci
If the transaction can be committed, then:
o Add the record <ready T> to the log
o Force all records for T to stable storage
o Send <ready T> message to Ci.
Phase 2: Recording the Decision
 T can be committed of Ci received a <ready T> message from all the
participating sites: otherwise T must be aborted
 Coordinator adds a decision record <commit T> or <abort T> to the log and
forces record onto stable storage.
 Coordinator sends a message to each participant informing it of the decision
(commit or abort)
 Participants take appropriate action locally.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 72


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Centralized 2PC:
P P

C P C P C

P P

Ready? Yes/no commit/abort? Committed/aborted

Phase 1 Phase 2
Distributed Locking:
The most common way in which access to items is controlled is by “locks”.
Lock manager is a part of DBMS that record, for each item I, whether one or more
transactions are reading or writing any part of item I. If so, the lock manager stops
another transaction from gaining access to item I.
The lock manager can store the current locks in a lock table which consists of
records (<item>, <lock type>, <transaction>). The meaning of record (I, L, T) is that
transaction T has a lock of type L on item I.
The DDBMS maintains a local lock manager at each location which
administers the lock and unlock requests for data items stored at that site. Locks
may be applied in two modes: shared and exclusive.
If a transaction locks a record in shared mode, it can read that record but
cannot update that record. If a transaction locks a record in exclusive mode, it can
both read and update the record and no other record can access the record while it
is exclusively locked. No two transactions can hold exclusive locks on same record
at the same time. Any number of transactions can be able to achieve shared locks
on the same record at the same time.
If there is only a single copy of a record, then the logical record is identical to
its only physical copy. Appropriate locks are maintained by sending lock-request
messages to the site at which the copy resides.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 73


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Distributed two phase locking:


Two phase locking is a process used to gain ownership of shared resources
without creating the possibility of deadlock.
There are 3 activities that take place in the two phase update algorithm:
1. Lock acquisition
2. Modification of data
3. Release Locks
The modification of data and subsequent release of the locks that protect the
data are generally grouped together and called the second phase.
Two phase locking prevents deadlock from occurring in distributed systems by
releasing all resources it has acquired. This means that no process is in a state
where it holds some shared resources and waiting for another process to release a
shared resource which it requires.
The resource (or lock) acquisition phase of a two phase shared data access
protocol is usually implemented as loop within which all the locks required to access
the shared data are acquired one by one. If any lock is not acquired on first attempt,
the algorithm gives up all the locks it had previously been able to get and starts to try
to get all the locks again.
This back-off and re-try strategy can be a problem in distributed systems. If a
single problem never acquires all the locks needed for it to continue execution, it can
lead to process starvation.
More complicated problems arise when two processes compete over locks.
One way to prevent this is to order the locks in a global sequence and require the
processes to acquire the locks in that sequence.
Time stamping:
A time stamp is a label or key that contains the current simulation time. An
Event Log adds this key to an entity when it either enters or leaves a process or
activity.
Time stamping can be performed upon entry (and/or) exit from an activity.
Time stamp specifications can be defined between two stamp keys enabling the
monitoring of cycle time and counts between two time stamps.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 74


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

1. Define start and stop keys, select statistics options and press the OK
button.
2. Define as many start and end keys that you desire reporting on and
press the close button when finished.
3. The next step is to add the start and end keys to the Event Logs on the
activities or processes that the cycle time and counts will be monitored
between.
Time stamp based concurrency control protocols can be used in distributed systems.
 Each transaction must be given a unique timestamp.
 Main problem: how to generate a time stamp in distributed manner.
o Each site generates a unique local timestamp using either a logical
counter or the local clock.
o Global unique time stamp is obtained by concatenating the unique
local time stamp with unique identifier.

Local unique site


time stamp identifier

Global unique identifier

 A site with a slow clock will assign smaller time stamps.


o Still logically correct: serializability not affected
o But: “disadvantages” transactions
 To fix this problem
o Define within each site Si, a logical clock (LCi) which generates the
unique local time stamp.
o Require that Si advance its logical clock whenever a request is
received from a transaction Ti with timestamp <x, y> and x is greater
than the current value of LCi.
o In this case, site Si advances its logical clock to the value x+1.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 75


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

CLIENT SERVER SYSTEMS:


The term client/server was first used in 1980s in reference to personal
computers (PCs) on a network. The client/server software architecture is a message-
based and modular infrastructure that is used to improve usability, flexibility,
interoperability and scalability. A client requests services and a server provides
services.
A single machine can be both client and server depending on the software
configuration. In a network environment, a file server stores files required by users
on the network. When users need data from a file, the entire file is sent. In
client/server architecture, server is a computer providing data to the clients, which
are the computers that are connected to a network and people use to access data
stored on the server.
Client/server architecture may be either two-tier or three-tier. In two-tier
architecture, the server performs database functions and the clients perform
presentation functions. The term fat client refers to an arrangement where the clients
perform business functions. If the business functions reside on the server, each
client is called a thin client.
In three-tier architecture, the clients perform the presentation functions, a
database server performs the database functions and separate computers called
application servers perform the business functions and act as interface between
clients and database server.
The advantages of using a client/server system instead of a file server are:
 Lower network traffic
 Improved processing distribution
 Thinner clients
 Greater processing transparency
 Increased network
 Hardware and software transparency

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 76


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

 Improved security
 Decreased costs and increased scalability

Client 3
Client 1 Client 2

NETWORK

Server

CLIENT/SERVER DATABASE SYSTEMS:


Client/server systems are constructed so that the database can be maintained
on a central computer known as server and can be shared among several users.
Users access the server through a client or server application:
In a two-tier client/server system, users run an application on their local
computer known as client that connects over a network to the server. The client
application runs both business logic and the code to display output to the user and is
also known as thick client.
In a multi tier client/server system, the client application logic is run in two
locations:-
The thin client is run on the user’s local computer and is focused on displaying
results to the user.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 77


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

The business logic is located in server applications running on a server. Thin


clients request functions from the server application. The server application opens
connections to the database server.
Client computer Client computer

SQL Server Client SQL Server Client


Application Application

Database computer

SQL Server SQL Server Client


Application

Internet server

Server Internet
Application Information Server

Internet clients

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 78


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Advantages of storing the data in the server:


 Each data item is stored in a central location where all users can work
with it.
 Business and security rules can be defined one time on the server and
enforced equally among all users.
 Hardware costs can be minimized because the data is not stored on
each client. Clients do not want to give space for storing data.
 The server can be configured to optimize the disk I/O capacities.
 The server can be stored in a secure location and equipped with
devices.
 Maintenance tasks such as backing up and restoring data are
simplified.
Classic Client/Server Architecture:
Client machines:-
o Run own copy of operating system.
o Run one or more applications using client’s CPU & memory.
o Application communicates with DBMS server running on server machine
through a Database Driver.
o Examples: PCs with MS windows operating system
Server machines:-
o Run own copy of operating system.
o Run a DBMS that manages a database.
o Accepts connections from client machines and submits transactions to DBMS.
o Examples: RDBMS such as Oracle Server, Sybase, DB2 etc.
Middleware:-
o Small portion of software that sits between client and server.
o Establishes a connection from the client to the server and passes commands.
o Examples: Sybase open client and open server, Client application enablers.
Business rules may be enforced at:
o The client application called “Fat Clients”
o Entirely on the database server called “Thin Clients”
o A mix of both.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 79


JAAGRUTHI DEGREE & PG COLLEGE BCOM CA I YEAR II SEM

Advantages of Client/Server:-
1. Processing of the entire database is spread over clients and server.
2. DBMS can achieve high performance.
3. Client applications can take full advantage of advanced user interfaces.
Disadvantages of Client/Server:-
1. Implementation is more complex.
2. It is possible that network is not well suited for client/server communications.
3. Additional load on DBMS server to handle concurrency control.

Need for Client Server Computing:


Client/Server computing is a computing model in which client and server
computers communicate with each other over a network. In client/server computing,
a server takes requests from client computers and shares its resources, applications
and/or data with one or more client computers on the network, and a client is a
computing device that initiates contact with a server in order to make use of a
shareable resource.
1.Distributed presentation: The server and the client partly handle the
presentation
2. Remote presentation: The client handles or controls the entire presentation
3. Distributed logic: The server and the client partly handle the application
logic
4. Remote data management: The server handles or controls the entire
Database management
5. Distributed database: The server and the client partly handle the Database
management
Client/Server Computing is proved much cost efficient and feasible in a mainframe
environment.

RELATIONAL DATABASE MANNGEMENT SYSTEM Page | 80

You might also like