0% found this document useful (0 votes)
77 views80 pages

RDBMS Iii Sem

Uploaded by

laxman Nyamtabad
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
0% found this document useful (0 votes)
77 views80 pages

RDBMS Iii Sem

Uploaded by

laxman Nyamtabad
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

JAAGRUTHIDEGREE&PGCOLLEGE

A ZADROA DBHO NGIRNA LGONDA(D)


UNIT-1
DATABASECONCEPTS

Data:
Dataisnothingbutacollectionofrawfactsofapersonorathing.
Ex:collectionofnumbers,charactersandtext.

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

MetaData:
Metadataisdataaboutdata.(Or)metadataisdatathatdescribesotherdata.
Ittellsushow,whenandbywhomthedataismodified.

DataBase:
Databaseisanorganizedcollectionofdata.
(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.

Thefollowingarethevariousdatabases:

i) Ms-Access.
ii) Oracle.
iii) Sybase.
iv) Db2.
v) Teradata
vi) SQLserver.
vii) Foxpro.

RelationalDatabase:
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. Inrelational database,the data is organized in the formof tables.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|2
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.

EvolutionofDatabaseSystem:
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
takesalongtime.Thedrawbacksoffilemanagementsystemareupdatingormodifying 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
ObjectOriented

TraditionalFiles Relational

Network ObjectRelational

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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|3
1990’s:
In 1990’s Object oriented & Object relational databases were developed.
Datain the database is treated as object.
Today:
Inthisdecade,non-relationaldatabasesareusedlikeXMLdatabase.

FILEORIENTED(BASED)SYSTEMS
Fileorientedsystemisanearliersystemtodatabases.Thetypicalfile
orientedsystemissupportedbyaconventionaloperatingsystem.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.
Thefollowingarethedisadvantagesoffileorientedsystem:
1. DataRedundancyandInconsistency:
Since files and application programs are created by different
programmers,thefileswillhavedifferentformatsandprogramsmaybe
writteninseveralprogramminglanguages.Thesamepieceofinformation may be
duplicated in several places. This redundancy leads to higher storage, access
cost and may lead to data inconsistency.
2. Difficultyinaccessingdata:
The conventional file processing environments do not allow
neededdata to be retrieved in a convenient and efficient manner. Better data
retrieval systems must be developed for general use.
3. DataIsolation:
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. Concurrentaccessanomalies:
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. Securityproblems:
Not every user of the database system should be able to access all the
data. Itis difficult to enforce security constraints in file oriented systems.
6. Integrityproblems:
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. Atomicityproblems:
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 restoredto
the consistent state existed before the failure.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|4
AdvantagesofDBMSoverFilebasedsystem:

DBMS provides the following advantages compared with file based


system.
1. ImprovedDataSharing:
TheDBMSoffersaccesstomoredata.Itoffersdatasharingamongits
users.
2. ImprovedDataSecurity:
Accessing the data by many users gives risks to the data security. So
DBMS provides better data privacy & security policies.
3. Minimizeddataredundancy:
Data inconsistency exists when different version of the same data
appears in different places. DBMS greatly reduced data inconsistency.
4. Betterdataintegration:
DBMS provides an integrated view of the entire organization. It
integrates the dataof all the departments and maintains it asone data set.
5. Improveddataaccess:
The DBMS provides quick answers to queries. A query is a data
manipulation request issued to the DBMS.
6. Improveddecisionmaking:
Better managed data provides better quality information and
knowledge. It is useful to make better decision.
7. Increasedend-userproductivity:
Theavailabilityofdataandinformationincreasesend-userproductivity.

DATAMODELS:

Datamodelisnothingbuthighleveldescriptionofdata

(Or)

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

Data models are classified into five types. They are:

1) Entity-Relationshipmodel
2) Objectorientedmodel
3) Relationalmodel
4) Hierarchicalmodel
5) Networkmodel
1) ERMODEL:-
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|5
ThefollowingarethecomponentsofERdiagram.
Rectanglerepresentsanentityset.
Ellipsesrepresentalistofattributes.
Diamondrepresentsrelationshipamongtheentities.
Lines represents link between attributes to the entity sets and entity
sets to relationship.

B name
Cname
Bid
Cid Baddress
Caddress

borrows from
CUSTOMER LOAN BANK

BMobile Bbranch
Salary
Mobileno

2) Objectorientedmodel:-
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) Relationalmodel:-
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|6
CUSTOMERTABLE
Cust–no Cust–name Cust–address

11500 Anil Hyd


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

4) Hierarchicalmodel:-
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

Therecordsinthedatabaseareorganizedascollectionoftrees.

5) NETWORKMODEL:-
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

RELATIONALDATABASEMANNGEMENTSYSTEM Page|7
DATABASEADMINISTRATOR(DBA):

DBA is the person who is responsible for complete maintenance and effective
working ofthe database. DBA is also responsible for managing databases.
ROLESOFDBA:
ThefollowingaretherolesofDBA.
Databasedesign:
Designisoftwotypes
1) Conceptualdesign
Conceptual data base design consists of data definitions, relationship
between data.
2) Physicaldesign
Physical database design determines the physical structure of
database and access methods.
UserTraining:
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.
DatabaseSecurityandIntegrity:
DBAcontrolsdataaccessbyusingauthenticationandauthorization.
--Authenticationistheprocessofcheckingwhethertheuserisvalidornot
--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.
DatabaseSystemPerformance:
The DBA should include technical people to identify and solve system
response-time problems. The DBA may maintain redundant/duplicate copies of dataat
different locations/places to improve the system performance.

FunctionsofDBA:
ThefollowingarethefunctionsofaDBA:
1. SchemaDefinition:-
TheDBAcreatesdatabaseschemabyexecutingDDLstatements.
Schemaincludesthelogicalstructureofdatabase.

2. DataDefinition:-
The DBMS provides functions to define the structure of the data in
application.Itincludesdefiningandmodifyingrecordstructure,typeandsize of fields.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|8
3. DataManipulation:-
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. Grantingauthorizationfordataaccess:-
TheDBAprovidesdifferentaccessrightstotheusersaccordingtotheirlevel.
5. RoutineMaintenance:-
SomeoftheroutinemaintenanceactivitiesofaDBAaregivenbelow.
 Takingbackupofdatabase.
 Ensuringenoughdiskspace.
 Ensurethatperformanceisnotdegraded.
 Performancetuning.
6. Security:-
TheDBAfocusesonsecuritymethodstopreventunauthorizedusers from
accessing the database.
7. BackupandRecovery:-
Backupandrecoveryproceduresaretestedregularlytomaintain
effectiveness in restoring database after failure.
8. PerformanceEvaluation:-
System performance is monitored by collecting statistics on transaction
volume, response time, error rates.
9. IntegrityChecking:-
Scheduleshavebeendevelopedfortestingtheintegrityofthedata stored in
the database.

DATABASEAPPROCH:
Databaseapproachisawayinwhichdataisstoredinthedatabase.
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.
DataIndependence:
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.
Therearetwolevelsofdataindependence.
--PhysicalDataIndependence:
The ability to modify the physical schema without rewriting the
application programs.
--LogicalDataIndependence:
The ability to modify the conceptual schema without rewriting the
application programs.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|9
DataIntegrity:
TheDBMSenforcesintegrityrulestominimizedataredundancyand maximizedata
consistency.Thedata relationshipsare used to enforce data integrity.

ADVANTAGESOFDATABASEAPPROACH:
Thefollowingaretheadvantagesofdatabaseapproach.
1) ProgramDataIndependence:
The database allows data to change the data base without modifying
the application programs. This allows separation of database from the
application programs.
2) MinimalDataRedundancy:
The database approach does not eliminate redundancy completely,
butitprovidesthefacilitiestothedesignertocontroltheamountof redundancy.
3) ImprovedDataConsistency:
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) ImprovedDataSharing:
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) EnforcementOfStandards:
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) Improvedquality:
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.
ERModel:-

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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|10
-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:Ahumanbeing,computer,bike.
-Entityset:-
Acollectionofsimilarentitiesiscalledentitysetorentitytype.
Ex: All employees of an organization EMP.
All departments of a university DEPT.
TypesofEntities:-
--WeakEntity:-
Weakentityisanentitythatdependsonotherentityorentities.
Theweakentityisshownindoublerectanglebox.
--StrongEntity:-
Astrongentityisanentitythatdoesnotdependonotherentity
orentities.

FATHER

FAMILY

Inabovediagram,“Father”isastrongentityand“Family”isaweakentity.

-Attribute:-

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


entities

TypesofAttributes:-

--Simpleattribute:-
If an attribute cannot be divided into simpler components, it is a simple
attribute.
Ex:-EmpNo,StdNo
--Compositeattribute:-
If an attribute can be divided into components, it is called a composite
attribute.
Ex:-NameofstudentcanbedividedintoFirst-nameandLast-name
--Single-Valuedattribute:-
Ifanattributecantakeonlyasinglevalue,itisasinglevaluedattribute.
Ex:-ageofastudent

RELATIONALDATABASEMANNGEMENTSYSTEM Page|11
--Multi-Valuedattribute:-
If an attribute can take more than one value, it is a multi-valued
attribute. Multi-valued attribute is represented with double ellipse.
Ex:-Telephonenumber(Mobilenumber,Landline)

--Derivedattribute:-
An attribute which is calculated or derived from other attributes is
calleda derived attribute. Derived attribute is represented with dashed ellipse.
Ex:-Totalandaveragearecalculatedonmarksofthestudent.

Relationship:
A relationship is an association of two or more entities. A meaningful
relationship is called relationship set or relationship type.
Ex:- WorkingisarelationshipbetweenEMPandDEPT
DegreeofRelationship:-
Relationshipdegreemeansthenumberofentitiesinarelationship.
Relationshipscanbeclassifiedbytheirdegree.
UnaryRelationship:-
Inunaryrelationship,thereisonlyoneentity.

ENTITY

BinaryRelationship:-
Inbinaryrelationship,twoentitiesareinvolved.

Relation
ENTITY ENTITY
-ship

RELATIONALDATABASEMANNGEMENTSYSTEM Page|12
TernaryRelationship:-
Internaryrelationship,threeentitiesareinvolved.

Relation
ENTITY -ship
ENTITY

ENTITY

n-aryRelationship:-
Inthisrelationship,fourormoreentitiesareinvolved.

ENTITY

Relatio
ENTITY n-ship
ENTITY

ENTITY

RELATIONALDATAMODEL:
The primary concept of relational data model is a relation. Relations are same
as tables.
Arelationcontainsthefollowingrules:
Relationisatwo-dimensionaltable.
Attribute(field)isacolumninthetable.
Entriesinanycolumnareallofthesametype.
Atuple(record)isarowinthetable.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|13
--Key:-
Itisanattributeusedtoidentifydatainarelation.
--SimpleKey:-
Asimplekeycontainsasingleattributeinarelation.
--CompositeKey:-
Itcontainsmorethanoneattribute.
--SuperKey:-
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.
--CandidateKey:-
Itisanattributethatuniquelyidentifiesarow.
--PrimaryKey:-
A primary key is the candidate key which is selected as the principal unique
identifier.
Ex:-stdnoinstudentrelation
--ForeignKey:-
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.
--AlternateKey:-
Itisacandidatekeywhichisnotselectedtobetheprimarykey.
Ex:- If user forgets his registration number in an application, name &
date of birth is an alternate key.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|14
UNIT-2
DATABASEINTEGRITYANDNORMALIZATION

INTEGRITYCONSTRAINTS:
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.
--Domainconstraint
--EntityIntegrity
--ReferentialIntegrity
--Operationalconstraints
DomainConstraint:-
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:-NotNull,DefaultandCheckaredomainintegrityconstraints.
--NotNullConstraint:-
NULLinSQLindicatesdatawhichdoesnotexistinthedatabase.
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.
--DefaultConstraint:-
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.
--CheckConstraint:-
Check constraint is used to define a logical expression that valid data
when Insert or Update data is performed in a table ofrelational database.
EntityIntegrity:-
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|15
--PrimaryKeyConstraint:-
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.
--UniqueKeyConstraint:-
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.
ReferentialIntegrity:-
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
referencea 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 relationaldatabase.
OperationalConstraints:-
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|16
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.

TablewithMulti
ValuedAttributes
Remove multi
valuedattributes&d
efinePK
FIRSTNORMALFORM
(1NF)

RemovePartial
dependency

SECONDNORMAL
FORM (2NF)
RemoveTransitive
dependency

THIRDNORMALFORM
(3NF)
Make every
determinantas
candidate key
BOYCECODDNORMAL
FORM (BCNF)
Removemulti
valued
dependencies
FOURTHNORMAL
FORM (4NF)

Removeany
remaining
FIFTHNORMALFORM anomalies
(5NF)

FunctionalDependency:
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|17
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’.
Afunctionaldependencyinarelationisrepresentedbyanarrow( ).
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:
ConsiderthefollowingrelationSTUDENT

SNO SNAME COURSE FEE


LANGUAGEKNOW N

Thefunctionaldependencyinthisrelationcanalsobeshownas:

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.

Partialdependency:
A partial dependency is a functional dependency in which one or more
non key attribut5es are functionally dependent on part of the primary key.
Transitivedependency:
A transitive dependency is a functional dependency that exists between
two or more non key attributes.
Multivalueddependency:
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) FirstNormalForm(1NF)

RELATIONALDATABASEMANNGEMENTSYSTEM Page|18
2) SecondNormalForm(2NF)
3) ThirdNormalForm(3NF)
4) Boyce-CoddNormalForm(BCNF)
5) FourthNormalForm(4NF)
6) FifthNormalForm(5NF)
1) FirstNormalForm:
A relation is said to be in 1NF if it has no repeating groups (multi
valued attributes) and a primary key is defined.
ConsiderthefollowingrelationSTUDENT:

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.
Arelationcanbeconvertedinto1NFbyusingatwostepprocess.
Step1:
Create a new row for each value of the multi valued attributes and
supply missing values.
Step2:
Defineanappropriateandsuitableprimarykeyfortherelation.
For the above relation ‘STUDENT’ sno, language known
are to be selected as a composite primary key.
Asperstep1,step2STUDENTrelationcanberevisedas:
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

RELATIONALDATABASEMANNGEMENTSYSTEM Page|19
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 therelation‘STUDENT’isin1NF.
2) SecondNormalForm:
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

PARTIALDEPENDENCY

Theaboverelationisin1NFbutitcontainspartialdependency.
Thereisaprocesstoconvertarelationinto2NF.
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 LANGUAGEKNOWN

RELATIONALDATABASEMANNGEMENTSYSTEM Page|20
Nowtheaboverelationsarein2NF.

3) ThirdNormalForm(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:

RELATIONALDATABASEMANNGEMENTSYSTEM Page|21
PRODUCT

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

CUSTOMER

C-ID C-NAME C-CITY

Boyce-CoddNormalForm:
Sometimeseventhougharelationisin3NF,anomaliesmaystill
exist.
R.F.BoyceandE.F.Coddidentifiedtheproblemsin3NFand
proposedastrongerdefinitiontoitknownasBCNF.

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


every determinant is a candidate key.

ConsiderthefollowingrelationTIMETABLE

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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|22
Itgivesthefollowingrelation.

SECTION FACULTY SUBJECT TIME

PARTIALDEPENDENCY
The table contains partial dependency. It can be removed by
decomposing the table into 2 tables as shown below:
TIMETABLE

SECTION FACULTY TIME

FACULTY

FACULTY SUBJECT

NowthesetworelationsareinBCNF.
4) FourthNormalForm(4NF):
A relation is said to be in 4NF if it is in BCNF and it
does not contain multi valued dependencies.
Considerthefollowingrelation:

COURSE FACULTY BOOK

Java Kiran Dietel


Ramu Balaguruswamy
Raju
Oracle Ajay Peter
Codd Norton

RELATIONALDATABASEMANNGEMENTSYSTEM Page|23
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

FILEORGANIZATION:
Fileorganizationisawayofarrangingfilesonthediskandaccessmethod tells how
data is retrieved based on file organization.
Fileorganizationisthearrangementoffilesonthedisk.Itincludestheway how records
and blocks are placed on storage medium. File organization is themethod 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 basedon its typeofuse.
Sevenorganizationmodelsareusedtoaccessfilefromthesecondary memory device
with various techniques.
1. Sequential

RELATIONALDATABASEMANNGEMENTSYSTEM Page|24
2. Index-sequential
3. Hashed/Direct
4. Multi-key
5. Multi-list
6. Inverted
7. Heap
1. SequentialFileOrganization:
In sequential file organization, records are arranged sequentially. Amagnetic
tape file such as printer can only have a sequential organization. A
sequentiallyorganizedfilemaybestoredoneitheraserial-accessordirect access storage
medium.
The task of file handling is the responsibility of the system software knownas
Input-Output Control System (IOCS). Block is used to group a number of
consecutive records. IOCS take scare of blocking.
Beginningoffile Endoffile

RECORD RECORD RECORD ………. RECORD RECORD


1 2 3 (n-1) n

Advantagesofsequentialfileorganization:-
i) Simpletoimplement
ii) Requiresverylowsoftwaresupport
iii) Efficiencyofblockingisgood
iv) Blockingsavesinput-outputtimerequiredforhandlingafile
v) Storagespacecanbesaved.
Disadvantagesofsequentialfileorganization:-
i) Updatesarenoteasilydone.
ii) Randomaccessisnotpossible.
iii) Everyrecordmustberewrittentoprovidespacefornewfield.
AreaofUse:-
Sequentialfilesaremostfrequentlyusedincommercialbatchorienteddata processing
applications.
Ex:Payrollapplications

RELATIONALDATABASEMANNGEMENTSYSTEM Page|25
2. IndexSequentialFileOrganization:
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 keyfield.
Inindexfileorganization,therecordsarestoredinkeysequenceorder usually in
ascending order. Some index tables are also created and maintained withthe file. Index
table is used to identify the group ofrecords in the file.

SequentialIndexFile SequentialIndexFile
n=numberofrecords
Name$
Names$(1)
Recordnumber(1) Address$
Record 1
 City-state$
 Zipcode$

 Name$
Address$
Name$(n)
Record 2
Recordnumber(n) City-state$
Zipcode$




Record3

Advantagesofindexsequentialfileorganization:-
i) Inindexsequentialfileorganization,theiteminthetablecanbeexamined sequentially.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|26
ii) Itisveryusefulwhenarandomaccessofrecordsbyspecifyingthekeyis required.
iii) Updatingiseasilydone.
Disadvantages:-
i) Performancedecreasesasfilegrows.
ii) Mustfollowindexstructuretolocatedata.
iii) Expensivesystemaccessories.
AreaofUse:-
It supports applications that access individual records rather than searching
through the entire collection in sequence.
Ex:ReservationEnquirysystem
3. Hashed/DirectAccessFileOrganization:
Directfileorganizationalsoreferredasrandomorrelativeorganization.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
positionofrecordinthefile.Thesystemcandirectlylocatethekeytofindthe desired record
without searching any other records.

1 Rec001

2 Free

3 Rec003

4 Rec004

Free
5
Relative Free
Record 6
Rec007
Number 7

Rec325
325
Rec326
326
Free
327
Rec328
328

RELATIONALDATABASEMANNGEMENTSYSTEM Page|27
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
CPUcangodirectlytothedesiredrecordwithoutsearchingalltheotherrecordsin the file.
Direct access is used where file activity is low.
Advantages:-
i) Immediateaccesstorecordsforupdatingispossible.
ii) Transactionsneednotbestored.
iii) Differentdiscsarenotrequiredforupdatingrecords.
iv) Randominquiriesinbusinesssituationscanbeeasilyhandled.
Disadvantages:-
i) Datamaybeaccidentallyerasedorover-written.
ii) Lessefficientintheuseofstoragespace.
iii) Expensivehardwareandsoftwarearerequired.
iv) Systemdesigniscomplexandcostly.
v) Fileupdatingismoredifficultcomparedtosequentialfiles.
AreaofUse:-
A direct file organization is suitable for interactive online applications such as
airline and railway reservation systems.
4. Multi-KeyFileOrganization:

Multikeyfileorganizationisusedtoaccesstherecordsbyusingmorethan one key. It


allows multiple access paths each having a dissimilar key. There are
severalmethodsused toexecutemultikey fileorganization.Mostofthese methods are
based on building indexes to provide directaccess by the key value.
Twoofthecommonmethodsforthisorganizationare:
Multi-listfileorganization
Invertedfileorganization
5. Multi-ListFileOrganization:
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|28
6. InvertedFileOrganization:
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
pointersto 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:
Heapfilescanbecreatedanddestroyed.
Existingheapfilescanbeopenedandclosed.
Recordscanbeinsertedanddeleted.
Recordsareuniquelyidentifiedbyarecordid.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|29
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 ofthe 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. Verygoodmethodforbulkinsertion.
2. Fetchingofrecordsisfasterinsmallfiles.
Disadvantages:
1. Itisnotsuitableforlargerfiles.
2. Nopropermemorymanagement.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|30
UNIT-3
SQL-STRUCTUREDQUERYLANGUAGE

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
functionsof SQL are:
 Storedata
 Modifydata
 Retrievedata
 Deletedata
 Createtablesandotherdatabaseobjects
SQLEnvironment:
➢ Catalog:-
Asetofschemasthatdescribesdatabaseiscalledacatalog.
➢ Schema:-
Itisastructurethatcontainsdescriptionofobjects.
➢ DataDefinitionLanguage(DDL):-
Commands that define database which includes creating, altering and
dropping tables.
➢ DataManipulationLanguage(DML):-
Commandsthatmaintainsandqueryadatabase.
➢ DataControlLanguage(DCL):-
Commands that controls a database including, administrative privileges and
committing data.
RoleofSQLinDatabaseArchitecture:-
TheOracleRDBMSisavailableonmanyoperatingsystemplatforms.
 Oracle is a relational DBMS- even the data dictionary is simply a collection
of tables of data along with indexes and other objects.
 SQLhasabasicgrammarandsyntax.
 The functionality of SQL language is same on these operating system
platforms.
 UsingSQLdoesnotrequireprogrammingexperience.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|31
SQLStandards–theirCharacteristicsandBenefits:-
TheSQLstandardprovides:
 Specific syntax and semantics of SQL data definition & data manipulation
languages.
 Basicdatastructuresandoperations.
 Portabilityofapplications.
 Reducedtrainingcost.
 Productivity.
 Reduceddependence.

DATABASESCHEMA:
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.
Levelsofdatabaseschema:-
1. Conceptualschema:amapofconceptsandtheirrelationships.
2. Logicalschema:amapofentities,attributesandrelations.
3. Physicalschema:aparticularimplementationofalogicalschema.
4. Schemaobject,Oracledatabaseobject.
5. Schemaistheoverallstructureofthedatabase
EachDataSchemaincludes:-
o Alistofvariableswithdescription,definitionandformat.
o Alistofdomainswithdefinition.
o Alistofthemesandmoduleswithdefinitions.
SQLTABLES:
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.
Indatabaseterms,atableisresponsibleforstoringdatainthedatabase.
Database tables consist of rows and columns. Row contains each record in the table
and column is responsible for defining the type of data.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|32
SQLDATATYPES:-
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
storingnumbersand text.Every constant, variable and parameterhasa 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:-
Adatatypeusedtostorebinarydataordatawhichisbyteoriented.
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. Fixedlengthmemorystorage
b. CHARtakes1bytepercharacter
c. Usecharwhenthedatavaluesinacolumnareofsamesize.
VARCHAR:-
a. Variablelengthmemorystorage.
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|33
VARCHAR2:-
a. AreplacementforVARCHARinnewversionsoforacle.
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.

SQLCOMMANDS:
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:
DataDefinitionLanguage(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.
DataManipulationLanguage(DML)Commands:-
These SQL commands are used for storing, retrieving, modifying and
deleting data. These commands are SELECT, INSERT, UPDATE and
DELETE.
DataControlLanguage(DCL)Commands:-
These SQL commands are used for providing security to database
objects. These commands are GRANT and REVOKE.
TransactionControlLanguage(TCL)Commands:-
These SQL commands are used for managing changes affecting the
data. These commands are COMMIT, ROLLBACK and SAVEPOINT.

SQLCOMMANDS

DDL DML DCL TCL

Create Insert Grant Savepoint


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

RELATIONALDATABASEMANNGEMENTSYSTEM Page|34
DDLCommands:-
DDL Commands are used to create, modify and delete the structure of objectin
the database. The syntax of DDL commands always includestable keyword after the
command name.
 Create
 Describe/desc
 Alter
 Drop
 Truncate
 Rename
CREATETABLECommand:-
TheCREATETABLEstatementisusedtocreatetablestostoredata.Itis 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), ......... );
--tablenameisthenameofthetable.
--column1,column2,……arecolumnnames.
--datatypeisthedatatypeofcolumnslikechar,date,numberetc.
Ex:
SQL>CREATE TABLE emp(id number(5), name char(20), dept
char(10), sal number(10));
SQL>TableCreated
DESCRIBE/DESCTABLECommand:-
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
 PrimaryKey
Syntax:
DESC<tablename>;
EX:

RELATIONALDATABASEMANNGEMENTSYSTEM Page|35
SQL>DESCstd;
ALTERTABLECommand:-
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,modifytable/columns.
2. Addanddropconstraints.
3. Enableanddisableconstraints.
Syntax:
ALTER TABLE table_name ADD(new column data type(size));
ALTER TABLE table_name MODIFY(new column data type(size));
Syntaxtoaddacolumn:
ALTERTABLEtable_nameADDcolumn_namedatatype(size);
Ex:
SQL> ALTER TABLE emp ADD experience number(3);
SQL> Table altered
Syntaxtodropacolumn:
ALTERTABLEtable_nameDROPcolumn_name;
Ex:
SQL>ALTERTABLEempDROPlocation;

Syntaxtomodifyacolumn:
ALTERTABLEtable_nameMODIFYcolumn_namedatatype(size);
Ex:
SQL>ALTERTABLEempMODIFYsalnumber(15,2);
DROPTABLECommand:-
The DROP command is used to remove an object from the database. Once a
table is dropped we cannotgetit back.Itis used to destroya table structure.
Syntax:
DROPTABLEtable_name;
Ex:
SQL>DROPTABLEemp;
TRUNCATE:-
The TRUNCATE command is used to delete all the rows from the table and
free the memory space.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|36
Syntax:
TRUNCATETABLEtable_name;
Ex:
SQL>TRUNCATETABLEemp;
DifferencesbetweenDROPandTRUNCATE:-
If a table is dropped, all the relationships with other tables are not valid, the
integrityconstraintsaredropped.Ifwewanttousethetableagain,wehaveto 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.
RENAMECommand:-
RENAMEcommandisusedtochangethenameofatable.
Syntax:
RENAMETABLE<oldtablename>TO<newtablename>;
Ex:
SQL> RENAME TABLE emp TO employ;
SQL> Table Renamed

DMLCOMMANDS:
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.
TheDMLcommandsare:
➢ Insert
➢ Select
➢ Update
➢ Delete
INSERTCommand:-
This command is used to enter and store the values in the database. The data
valuesgivenbytheuserininsertstatementshouldmatchwiththedatatype
declaredfortheselectedcolumninthetable.SQLinsertcommandisimplemented in 3
methods.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|37
Simpleinsertstatement:-
Itisusedtoinsertasinglerowofvalueintheselectedtable
Syntax:
INSERT INTO <table name> values(column1 value, column2
value,……columnN value);
Ex:
SQL>INSERTINTOstudentvalues(1,’sam’,430,’Bcom’);
Partialinsertstatement:-
Itisusedtoentervaluesforselectedcolumnsbyleavingothercolumns.
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’);
Interactiveinsertstatement:-
Itisusedtoentermultiplevaluestotheselectedtablewithvariousvalues.
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:
INSERTINTO<tablename>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.
SELECTCommand:-
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|38
Syntax:
SELECT column-list FROM table-name
[WHERE clause]
[GROUP BY clause]
[HAVING clause]
[ORDER BY clause]
--WHEREclauseisusedtogiveconditionsandretrieveonlyselectedrecords.
--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.
ASELECTstatementisusedtodisplaytherecordsinmultiplemethodsas:
 Allrowsandallcolumns
 Selectedcolumnsandallrows
 Selectedrowswithallcolumns
 Selectedrowswithselectedcolumns
Ex:
SQL>SELECT*FROMstd;
SQL> SELECT sno, sname, dob FROM std;
SQL>SELECT*FROMstdWHEREsno=3;
UPDATECommand:-
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>UPDATEstdSETname=’akshay’WHEREsno=3;
DELETECommand:-
DELETE command is used to delete records from the table either single
record or multiple records based on a condition using WHERE clause.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|39
Syntax:
DELETEFROMtable-name[WHEREcondition];
Ex:
SQL>DELETE FROM std WHERE name=’priya’;
SQL> DELETE FROM std;
Thiscommanddeletesalltherowsfromthetableifnoconditionisspecified.
DCLCOMMANDS:
DCL commands allow database administrators to configure security access to
relational databases. Two types of DCL commands are GRANT and REVOKE. Only
databaseadministratororownerofdatabaseobjectcanprovide/removeprivileges on
database object.
GRANTCommand:-
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-nameisnameoftheusertowhomaccessrightisgranted.
--PUBLICisusedtograntaccessrightstoallusers
--Role-nameissetofprivilegesgroupedtogether
--WITH GRANT OPTION allows user to grant access rights to other
users.
EX:
SQL>GRANTSELECTONstudentTOjaya;
REVOKECommand:-
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]

RELATIONALDATABASEMANNGEMENTSYSTEM Page|40
--GRANT OPTION FOR removes the specified user’s ability to grant specified
permission to other users.
--CASCADErevokesthespecifiedpermissionfromanyusers.
EX:
SQL>REVOKESELECTONstudentFROMjaya;
TCLCOMMANDS:
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.
AROLLBACKisautomaticallyperformedwhen:
▪ ThedefaultactivationgroupendswithoutafinalCOMMIT
▪ 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.
SAVEPOINT:-
The SAVE POINT statement names and marks the current point in the
processing a transaction.
▪ Asimplerollbackorcommiterasesallsavepoints.
▪ 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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|41
EX:
SQL>SAVEPOINTss1;
SQLWHERECLAUSE:
SQL WHERE clause is used to specify a condition while getting the data from
singletable or joiningwithmultipletables.Ifthegivenconditionis satisfied thenonly
itreturnsspecificvaluefromthe table. WHEREclauseisusedtofilterthe records and fetch
only necessary records. The WHERE clause is not only used in SELECT statement
but also in UPDATE, DELETE statements etc.
Syntax:
SELECTcol1,col2,.….,colNFROMtable-nameWHERE[condition];
EX:
SQL>SELECT*FROMEmpWHEREsal>5000;
SQLNULLVALUE:
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 causeproblemswhenselecting data.ISNULLorIS 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;
GROUPBY&HAVING:
SQLGROUPBYaggregatescolumnvaluesintoasinglerecordvalue.
GROUPBYrequiresalistoftablecolumnsonwhichthecalculationsareperformed.
EX:
SQL>SELECTaddressFROMempGROUPBYaddress;
Address
Delhi

RELATIONALDATABASEMANNGEMENTSYSTEM Page|42
Mumbai
Indore
SQL returned the values that are unique. We can also use mathematical functions
with GROUP BY like SUM().
EX:
SQL>SELCTaddress,SUM(sal)AS“areawisetotalsal”FROMemp;
Address Areawisetotalsalary
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>SELECTaddress,SUM(sal)FROMempGROUPBYaddress
HAVINGSUM(sal)>1000;
Address Sal
Delhi 23000
Mumbai 8000
Indore 13000
SQLJOINS:
SQL Joins are used to relate information in different tables. A SQL
joincondition 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.
SQLjoinscanbeclassifiedintoEquijoinandNonEquijoin.
1. SQLEquijoin:
It is a simple SQL join condition which uses equal sign as comparison
operator. An equi-join is further classified into two categories:

RELATIONALDATABASEMANNGEMENTSYSTEM Page|43
a) SQLInnerJoin
b) SQLOuterJoin
a) SQLInnerJoin:-
Returns all the rows returned by the SQL query satisfy the SQL join
condition that is specified.
b) SQLOuterJoin:-
It returns all rows from both tables which satisfy the join condition along
with rowswhich do not satisfy the join condition from one ofthe tables.
SQLSelfJoin:-
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. SQLNonEquiJoin:
A Non Equi Join is a SQL join whose condition is established using all
comparison operators except equal operator like >, <, >=, <=.
Syntaxforjoiningtwotables:
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.
CROSSJOIN:
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:
Explicitcrossjoin
SQL>SELECT*FROMempCROSSJOINdept;
Implicitcrossjoin
SQL>SELECT*FROMemp,dept;
INNERJOIN:
Inner join is the most common join operation used in applications. It creates a
newresulttablebycombiningcolumnvaluesoftwotablesbasedonthejoin predicate.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|44
SQL specifies two different syntaxes to express joins: explicit join notation and
implicit join notation.
TheexplicitjoinnotationusestheJOINkeywordtospecifythetabletojoin and ON
keyword to specify predicates for the join.
Ex:
SQL>SELECT*FROMempINNERJOINdeptONemp.Did=dept.Did;
Theimplicitjoinnotationsimply liststhetablesforjoiningintheFROM clause of the
SELECT statement using commas to separate them.
Ex:
SQL>SELECT*FROMemp,deptWHEREemp.Did=dept.Did;
Theinnerjoinsarefurtherclassifiedintoequijoins,naturaljoinsorascrossjoins.
--EquiJoin:-
It is a comparator based join that uses only equality comparisons in the
join predicate.
Ex:
SQL>SELECT*FROMempJOINdeptONemp.Did=dept.Did;
Or
SQL>SELECT*FROMemp,deptWHEREemp.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*FROMempINNERJOINdeptUSING(Did);
--NaturalJoin:-
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 columnnames
in the joined tables. The resulting table contains only one column for each pair
of equally named columns.
Ex:
SQL>SELECT*FROMempNATURALJOINdept;
OUTERJOIN:
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.
Outerjoinsareclassifiedintoleftouterjoins,rightouterjoinsandfullouter
joins.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|45
--Leftouterjoin:-
The result of left outer join or left join for table A and B always containsall
records of the left table A even if the join condition does not find anymatching
record in the right table B.
Aleftouterjoinreturnsallthevaluesfromaninnerjoinplusallvalues in the left
table that do not match to the right table.
Ex:
SQL>SELECT*FROMempLEFTOUTERJOINdeptON
emp.Did=dept.Did;
--Rightouterjoin:-
Arightouterjoinorrightjoincontainsallrecordsoftherighttableeven if the join
condition does not find any matching record in left table.
Arightouterjoinreturnsallvaluesfromtherighttableandmatched values from
the left table.
Ex:
SQL>SELECT*FROMempRIGHTOUTERJOINdeptON
emp.Did=dept.Did;
--Fullouterjoin:-
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
NULLvaluesforeverycolumnofthe table.Forthoserecordsthatdonot match, a
single row will be produced in the result set.
Ex:
SQL>SELECT*FROMempFULLOUTERJOINdeptON
emp.Did=dept.Did;
SQLVIEWS:
To reduce a redundant data to the minimum, Oracle allows the creation of an
objectcalledaView.AviewismappedtoaSELECTstatement.TheSELECT 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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|46
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.
Aviewusedonlytolooktabledataiscalledread-onlyview.Aview usedto lookand
implement insert, update anddelete statementsis called updatable view.
Reasonstocreateaview:
 Whendatasecurityisrequired
 Whendataredundancyistobekeptminimum.
Creatingaview:
CREATE VIEW view-name AS SELECT column-list FROM table-
name[WHERE condition];
TheSELECTstatementisusedtodefinethecolumnsandrowstodisplayin the view.
Ex:
SQL>CREATEVIEWvempASSELECTeid,enameFROMemp;
Updatingaview:
ThedefinitionoftheviewcreatedinSQLcanbemodifiedwithout dropping it by
using following syntax:
CREATEORREPLACEVIEWview-nameASSELECTcolumn=listFROM
table-name WHERE condition;
Ex:
SQL>CREATE OR REPLACE VIEW vemp AS SELECt eid, ename, sal
WHERE sal>5000 FROM emp;
UpdatableandRead-OnlyVIEWs:
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 allowedon
read-only views.
Anupdatableviewisonethatcanhaveeachofitsrowsassociatedwith
exactlyonerowinbasetable.Whenaviewischanged,thechangespassthrough the view to
base table.
Updatable views in standard SQL are defined only for queries that meet these
criteria:

RELATIONALDATABASEMANNGEMENTSYSTEM Page|47
1. Theyarebuiltononlyonetable.
2. NoGROUPBYclause.
3. NoHAVINGclause.
4. Noaggregatefunctions.
5. Nocalculatedcolumns.
6. NoUNION,INTERSECTorEXCEPT.
7. NOSELECTDISTINCTclause.
Eachrowintheviewmapsbacktooneandonlyonerowinthebasetable.
DroppingViews:
Viewsliketablescanbedroppedfromtheschema.TheSQLsyntaxforthe statement is:
DROPVIEW<tablenamelist>;
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.
NESTEDQUERIES:
A nested query isa query thatis nested inside another query. The innerqueryis
always executed first by the RDBMS. A nested query is also known as a sub queryor
an inner query.
CharacteristicsofNestedquery:
➔ Anestedqueryisaqueryinsideaquery.
➔ Itcanbeexpressedinsideparenthesis.
➔ ThefirstqueryintheSQLstatementisknownasouterquery.
➔ ThequeryinsidetheSQLstatementisknownasinnerquery.
➔ Theoutputofaninnerqueryisusedastheinputfortheouterquery.
TypesofNestedqueries:
Thefollowingarethetypesofnestedqueries:
1. WHERESubqueries:
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>SELECTP_code,P_priceFROMPRODUCTWHERE
P_price>=(SELECTAvg(P_price)FROMPRODUCT);

RELATIONALDATABASEMANNGEMENTSYSTEM Page|48
2. INSubqueries:
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-descLIKE
‘%hammer%’ORP-descLIKE‘%saw%’);
3. HAVINGSubqueries:
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);

CORRELATEDSubQueries:
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.
ForExample:
FORX=1TO2
FORY=1TO3
PRINT“X=X”,“Y=Y”
END
END
willyieldtheoutput:
X=1Y=1
X=1Y=2
X=1Y=3
X=2Y=1
X=2Y=2
X=2Y=3

RELATIONALDATABASEMANNGEMENTSYSTEM Page|49
Foracorrelatedsubquery,theRDBMSworksasfollows;
1) Itinitiatestheouterquery.
2) Foreachrowoftheouterquery,itexecutestheinnerquery.
The query is called a correlated sub query because the inner query is related
to the outer query by referencing a column ofthe 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);

RELATIONALDATABASEMANNGEMENTSYSTEM Page|50
UNIT-4
TRANSACTIONSANDCONCURRENCYMANAGEMENT

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.
TransactionStates:
Eachandeverytransactionhasfollowing5states:
1. Active
2. Partiallycommitted
3. Committed
4. Failed
5. Aborted

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

RELATIONALDATABASEMANNGEMENTSYSTEM Page|51
4. Failedstate:
Ifatransactioncannotproceedtotheexecutionstatebecauseof failure of
system or database, then the transaction issaid to be in failed state.
5. Abortedstate:
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.

TransactionProperties(ACIDProperties):
EachtransactionmusthaveAtomicity,Consistency,IsolationandDurability.
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
cannotbe 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
T1iscompleted.ThispropertyisparticularlyusedinMulti-userdatabase environment.
Durability:
Durability ensures that once transaction changes are done (committed) they
cannot be undone or lost even in the event of system failure.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|52
ConcurrentTransactions:
When many transactions take place at the same time, they are called
Concurrent transactions. Managing the execution of concurrent transactions is called
concurrency control.
SerializableSchedules:
A schedule is a process of grouping the transactions into one and executing
them in a predefined order. Aschedule is required in a database because whensome
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.
LockingProtocol:
A locking protocol is a set of rules that describes how the database entities
can be accessed.
ConcurrencyControl:
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 asaccess. In this typeof
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 unlessit gets the access to thatparticular data.

TheselocksarebroadlyclassifiedasBinarylocksandshared/exclusivelocks.

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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|53
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
reador write the data. When a data is read from the database, then its lock is shared
i.e.;thedatacanbereadbyothertransactiontoobutitcannotbechangedwhile retrieving the
data.

Lockbasedprotocolsareof4types

SimplisticLockProtocol:-Asthename suggestsitisthesimplestwayoflocking 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-claimingProtocol:-In this protocol,itevaluates the transaction tolistallthe data


items on which transaction needs lock. It then requests DBMS for the lock on all
thosedataitemsbeforethetransactionbegins.IfDBMSgivesthelockonallthe 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 toexecute,itstartsrequestingfor thelocksthatitneeds.Itgoeson 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 phaseoflocks.

Forexample,ifwehave to calculate totalmarksof3subjects,then this protocolwill go


onasking for the locks on subject1 marks, subject2 marks and then subject3marks.As
and when itgets the locks on the subjectmarks it reads the marks. It does

RELATIONALDATABASEMANNGEMENTSYSTEM Page|54
not wait till all the locks are received. Then it will have total calculation. Once it is
complete itrelease 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 isfully complete, it releasesall the locks together.
 TimeStampBasedProtocol:-
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.
Supposetherearetwotransactions T1andT2.SupposeT1has entered the
system at time 0005 and T2 has entered the system at 0008 clock
time.PrioritywillbegiventoT1toexecutefirstasitisenteredthesystem 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.
Accordingtothisprotocol:
IfatransactionTisareadtransactionondataXthen

RELATIONALDATABASEMANNGEMENTSYSTEM Page|55
Thisalgorithm states that ifthere is an active write operation on data Xwhena
transaction Tisrequesting for X, then reject the transaction T. Ifthe transaction
Tisstartedassoon aswrite iscompleteornogoingwrite operation onX,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.

 IfatransactionTisawritetransactionondataXthen

Thisalgorithmdescribes aboutwrite operation.Ifthere isan active read orwrite 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:
Deadlockoccurswhentwotransactionswaitforeachothertounlockdata.
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|56
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.

Deadlockavoidance

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
oneof the methods for detecting the deadlock situation. But this method is suitable
for smaller database. For large databasedeadlock 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 T1to
T2. If T2 releases the resource R, then this arrow is deleted.

DeadlockPrevention
The DBMS verifies each transaction and sees if there can be
deadlocksituationupon execution ofthe transaction.Ifit findseverything isfine,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.

Therearedifferentmethodstopreventthedeadlock

Wait-DieScheme
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|57
SupposeT1andT2betwotransactionsandlettimestampofany transactionTbe 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
forexecution.Thatmeansifayoungertransactionhaslockedsomeresource and
older transaction is waiting for it, then older transaction is allowed waitforit till it
is available.
 If T1 is oldertransaction and hasheld some resource with itand ifT2 is waiting
for it, then T2 is killed and restarted latter with random delay but withthe 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 itwaits


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 liketaking
time, all this happens in fraction of seconds and we cannot really observe the start/
delay/ restart / End.

WoundWaitScheme
In this method, if an older transaction requests for a resource held by younger
transaction, then older transaction forces younger transaction to kill the
transactionand release the resource. The younger transaction is restarted with
minute delay but with same timestamp.Iftheyounger transaction
isrequestingaresourcewhich is held by older one,thenyounger transaction isasked to
wait till olderreleases it.

OPTIMISTICCONCURRENCYCONTROL:
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 operationsare rare and that it is better to let transactionsrun
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.
Inoptimisticmethods,eachtransactionmovesthroughthefollowingphases:
a) Readphase.
b) Validationorcertificationphase.
c) Writephase.

a. Readphase:
In a Read phase, the updates are prepared using private (or local) copies (or
versions)ofthe granule.In thisphase,thetransactionreadsvaluesofcommitted data
fromthe database, executesthe needed computations, and makes the updates

RELATIONALDATABASEMANNGEMENTSYSTEM Page|58
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. Validationorcertificationphase:
In a validation (or certification) phase, the transaction is validated to assure that
the changes madewill not affect the integrity and consistency ofthe 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 :

 Seenallmodificationsoftransactionscommittedafteritstarts.
 Notreadgranulesupdatedbyatransactioncommittedafteritsstart.

c. Writephase:
Ina Writephase,thechangesarepermanentlyappliedtothedatabaseand the
updated granules are made public. Otherwise, the updates are discarded and the
transactionisrestarted.ThisphaseisonlyfortheRead-Writetransactionsandnot for Read-
only transactions.
AdvantagesofOptimisticMethodsforConcurrencyControl:
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.
ProblemsofOptimisticMethodsforConcurrencyControl:
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.
ApplicationsofOptimisticMethodsforConcurrencyControl:
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

RELATIONALDATABASEMANNGEMENTSYSTEM Page|59
DATABASEBACKUPANDRECOVERY:
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 losscan be partial
ortotal.Apartiallossiscausedbyaphysicallossofpartofthedatabaseorwhenpart
ofthedatabasehaslostitsintegrity.Atotallossmeansthatthedatabasecontinues to exist but
itsintegrity isentirely lostor the entire database isphysically lost.
Thebackupandrecoverymeasuresmustincludeatleast:
--Periodicdataandapplicationsbackups:-
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 backupdate.
Aconcurrentbackup takesplace while theuser isworking on the database.
--Properbackupidentification:-
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.
--Convenientandsafebackupstorage:-
Theremustbemultiplebackupsofthesamedataandeachbackupcopy 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?
--Physicalprotectionofbothhardwareandsoftware:-
Protectionmightincludetheuseofclosedinstallationswithrestrictedaccess
aswellaspreparationofcomputersitestoprovideairconditioning,backuppower and fire
protection.
--Personalaccesscontroltothesoftwareofadatabaseinstallation:-
Multilevel passwords, privileges, hardware and software challenge/response
tokens can be used to properly identify authorized users of resources.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|60
--Insurancecoverageforthedatainthedatabase:-
TheDBAmustsecureaninsurancepolicytoprovidefinancialprotectionin the event of
database failure.
SourcesofFailure:
1. Systemerrors:-
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. Hardwarefailures:-
Twomostcommontypesofhardwarefailuresarediskfailureandloss 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. Logicalerrors:-
Bad data or missing data are common conditions that may stop the
program continuing with normal execution.
RecoveryProcedures:
Tomaintaindataintegrity,atransactionmustbeinoneofthefollowingtwo
states:
1. Aborted:-
A transaction may not always complete its process successfully. Tomake
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.
DatabaseBackups:
Databasebackupscanbeeitherphysicalorlogical.
Physical backups are primary concern in backup and recovery strategy
whichare copies of physical database files.
Logicalbackupscontainlogicaldatasuchastablesandstoredprocedures.
Logicalbackupscansupplementphysicalbackups.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|61
Physicalbackupshavelargegranularityandlimitedtransportabilitybutare very fast.
Logical backups have fine granularity and complete transportability but are slower than
physical backups.
DATABASESECURITY:
Unauthorizedaccesstothedatabaseincludesthefollowing:
 Theftofinformation
 Unauthorizedmodificationofdata
 Unauthorizeddestructionofdata
Databasesecuritymethodsfocusonpreventingunauthorizedusersfrom 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
systementry is an authorizeduser. Hisor her identity may be establishedby
o Somethingtheuserknowssuchaslog-onnumberandpassword
o SomethingtheuserpossessessuchasaplasticIDcard
o A physical representation of the user such as finger print or voice print.
Authorizationallowsthedatabaseuserstoaccesscertainpartofdatabase.Theprocess of
verifying the identity of a user is called as authentication.
--PasswordAuthentication:-
In this scheme, the user is asked to enter the user name and password to log
intothedatabase.DBMSthenverifiesthecombinationofusernameandpassword to
authenticate the user and allows him the access to the database if he is an authorized
user otherwise access is denied.
--AccessControl:-
Most database users need only a small portion of database. Allowing them
access to whole database is undesirable. Thus an organization should develop
effectivesecuritypolicytoenableagroupofuserstoaccessonlyarequiredportion of the
database. Once the security policy is developed, it should be enforced toachieve the
level of security required.
AuthorizationandViews:-
Itisusedtograntprivilegestouserswhichhelpthemtoaccesscertain portion of the
database. Each user is allowed to perform only necessary operation on
thedatabasethatisrequiredtoperformtheirfunction.Thepersonwhois responsible for
granting privileges to database users is called authorizer.
Theauthorizationinformationismaintainedinatablecalledaccessmatrix. 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 unauthorizedaccess. Subject
is an active user or account who operates on various objects in the database.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|62
Aviewisameansofprovidinguserwithapersonalizedmodelofthe 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
ofaccesscontrolisautomaticallyobtained.Acombinationofrelational-levelsecurity and
view-level security can be used to limit a user’saccess to the data thatuser needs.
--TypesofViewAccess:-
Different types of access authorization may be allowed for a particular view as
follows:
o Readauthorization
o Insertauthorization
o Updateauthorization
o Deleteauthorization
Encryption:
Encryptionisaprocessofmaintainingdatasecurityinaninsecure 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.
--Simplesubstitutionmethod:-
Thismethodshiftseachlettertoitsimmediatesuccessorinthe alphabet.
Better encryption schemes use an encryption key.
--Poly-alphabeticsubstitutionmethod:-
Alignthekeybelowtheplaintextrepeatingitasmanytimesas necessary for the
plain text to be completely covered.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|63
UNIT-5
DISTRIBUTEDANDCLIENTSERVERDATABASES

DISRIBUTEDDATABASES:

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.

TypesofDDBMS:

DDBMSarebasicallydividedinto2majortypes:
Homogeneousdistributeddatabase:-
o Allsiteshaveidenticalsoftware
o Agreetocooperateinprocessinguserrequests
o Appearstouserasasinglesystem
Heterogeneousdistributeddatabase:-
o Differentsitesmayusedifferentschemasandsoftware
o Differenceinschemaisamajorproblemforqueryprocessing
o Differenceinsoftwareisamajorproblemfortransactionprocessing
o Providesonlylimitedfacilitiesforcooperationintransactionprocessing
DistributedDatabase:
A logically inter-related collection of shared data, physically distributed over a
computer network.
DistributedDBMS(DDBMS):
It is a software system that permits the management of the distributed
database and makes the distribution transparent to users.
CharacteristicsofDDBMS:
A DDBMS control the storage and processing of logically related data over
inter connected computer systems in which both data and processing functions are
distributedamong several sites. The following are the characteristicsofDDBMS:

RELATIONALDATABASEMANNGEMENTSYSTEM Page|64
o Application interface to interact with the end user, application programs
and other DBMSs.
o Validationtoanalyzedatarequestsforsyntaxcorrectness.
o Queryoptimizationtofindbestaccessstrategy.
o Mappingtodeterminethedatalocationoflocalandremotefragments.
o I/Ointerfacetoreadorwritedatafromortopermanentlocalstorage.
o Securitytoprovidedataprivacyatbothlocalandremotedatabases.
o Backup and recovery to ensure the availability and recoverability of the
database in case of failure.
o Databaseadministrationfeaturesforthedatabaseadministrator.
o Concurrencycontroltomanagesimultaneousdataaccess.
o Transaction management to ensure that data moves from one
consistent state to another.
AdvantagesofDDBMS:
1. Dataarelocatedneargreatestdemandsite:
The data in a distributed database system are dispersed to match
business requirements which reduce the cost of data access.
2. Fasterdataaccess:
Endusersworkwithonlyalocallystoredsubsetofcompany’sdata.
3. Fasterdataprocessing:
A distributed database system spreads out the systems workload by
processing data at several sites.
4. Growthfacilitation:
New sites can be added to the network without affecting the operations
of other sites.
5. Improvedcommunications:
Because local sites are smaller and located closer to customers, they
have better communication among departments, customers and company
staff.
6. Reducedoperatingcosts:
It is more cost-effective to add work station to a network than to
updatea mainframe system.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|65
7. Userfriendlyinterface:
TheGraphicalUserInterface(GUI)simplifiestraininganduseforend
users.
8. Lessdangerofasingle-pointfailure:
When one of the computers fails, the work load is picked up by other
work stations.
9. Processorindependence:
An end user’s request is processed by any processor at the data
location.
DisadvantagesofDDBMS:
1. Complexityofmanagement&control:
Applications must recognize data location and they must be able to
combine data from various sites.
2. Technologicaldifficulty:
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. Lackofstandards:
Therearenostandardcommunicationprotocolsatdatabaselevel.
5. Increasedstorageandinfrastructurerequirements:
Multiple copies of data are required at different sites which require
additional disk storage space.
6. Increasedtrainingcost:
Trainingcostsaregenerallyhigherinadistributedmodel.
7. Costs:
Distributeddatabasesrequireduplicatedinfrastructuretooperate.
Needfordistributeddatabases:
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
ableto access data maintained at other locations.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|66
The reasons for development and use of distributed database systems
include:
1. Organizations have branches or divisions in different locations. During
businessoperations,transactionsareprocessedagainstlocal 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 computerfails
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.

STRUCRUREOFDISTRIBUTEDDATABASE:
The design of a distributed database system is a complex task. We should be
very carefulwhile considering the objectives and strategies to be servedby thedesign
and parallel decisions must be made as how data is to be distributed among various
network sites.
StrategiesandObjectives:
Some of the strategies and objectives that are common to most implementations of
distributed database systems are as follows:
--LocationTransparency:-
Location transparency enables a user to access data without knowing
the site at which the data reside.
--ReplicationTransparency:-
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.
--ConfigurationIndependence:-
Configuration independence enables the organization to add or replace
hardware without changing the existing software components of DDBMS.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|67
--Non-homogeneousDBMSs:-
It is sometimes desirable to integrate databases maintained by different
DBMSsondifferentcomputers.Oneapproachofintegratingthesedatabases is to
provide a single user interface that can be used to access the data maintained
by the non homogeneous DBMSs.
DataReplication:
Data replication refers to the storage of data copies at multiple sitesserved bya
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
sharethe 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.
AdvantagesofReplication:-
➢ Availability
➢ Parallelism
➢ Reduceddatatransfer
DisadvantagesofReplication:-
➢ Increasedcostofupdates
➢ Increasedcomplexityofconcurrencycontrol
Threereplicationscenarios:-
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 Anunreplicateddatabasestoreseachdatabasefragmentatasinglesite.
Databasereplicationcanbedoneinatleast3differentways:-
--Snapshotreplication:
Data on one server is simply copied to another server or to another
database on the same server.
--Mergingreplication:
Datafromtwoormoredatabasesiscombinedintoasingledatabase.
--Transactionalreplication:
Users receive full initial copies of the database and then receive
periodic updates as data changes.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|68
DatabasePartitioning:
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.
DataFragmentation:
Data fragmentation allows to break a single object into two or more segments
or fragments.Each fragment can be stored atany siteover a computer network.
Fragmentationaimstoimprove:
✓ Reliability
✓ Performance
✓ Balancedstoragecapacityandcosts
✓ Communicationcosts
✓ Security
Thefollowinginformationisusedtodecidefragmentation:
Quantitativeinformation:
Frequency of queries, site, where query is run and selectivity of queries
etc.
Qualitativeinformation:
Typesofaccessofdata,read/writeetc.
Thereare3typesofdatafragmentationstrategies:
 Horizontalfragmentation:-
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|69
 Verticalfragmentation:-
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.
 Mixedfragmentation:-
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).
AdvantagesofFragmentation:
Horizontal:
o Allowsparallelprocessingonfragmentsofarelation.
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-idattributeallowsefficientjoiningofverticalfragments.
Verticalandhorizontalfragmentationcanbecombined:
o Fragmentsmaybesuccessivelyfragmentedtoanarbitrarydepth.
Replicationandfragmentationcanbecombined:
o Relation is partitioned into several fragments. System maintains several
identical replicas of each such fragment.
DataIntegrity:
As the data is distributed, the transaction activities may take place at a
number ofsites and itcan bedifficultto maintaina time orderingamong actions.
When two or more transactions are executing at the same time and both
require accessto the same data in order tocomplete their processing isa problem.
Most concurrency control algorithms for distributed database systems
usesome form of check to see that the result of a transaction is the same as if its
actions were executed serially.
Toimplementconcurrencycontrol,thefollowingmustbeknown:
1. Thetypeofschedulingalgorithmused
2. Thelocationofscheduler
3. Howreplicateddataiscontrolled

RELATIONALDATABASEMANNGEMENTSYSTEM Page|70
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.
TwoPhaseCommitProtocol(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.
➢ Commitprotocolsareusedtoensureatomicityacrosssites.
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
➢ Thetwophasecommitprotocoliswidelyused
➢ The three phase commit protocol (3PC) is more complicated and more
expensive but avoids some drawbacks of two-phase commit protocol
Two-phasecommitprotocol:-
➢ 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.
➢ Theprotocolinvolvesalllocalsitesatwhichthetransactionisexecuted
➢ Let T be a transaction initiated at site Si and let the transaction coordinator
at Si be Ci.
ImplementationProcess:-
Phase 1: The coordinator gets the participants ready to write the results into
database.
Phase2:Everybodywritestheresultsintodatabase
--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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|71
Globalcommitrule:
--Thecoordinatorabortsiffatleastoneparticipantvotestoabort.
--Thecoordinatorcommitsiffalltheparticipantsvotetocommit.
Phase1:obtainingaDecision
➢ CoordinatorasksallparticipantstopreparetocommittransactionTi.
o Ci adds the records <prepare T> to the log and forces log to stable
storage
o Sends<prepareT>messagestoallsitesatwhichTexecuted.
➢ 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
Ifthetransactioncanbecommitted,then:
o Addtherecord<readyT>tothelog
o ForceallrecordsforTtostablestorage
o Send<readyT>messagetoCi.
Phase2:RecordingtheDecision
➢ 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)
➢ Participantstakeappropriateactionlocally.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|72
Centralized2PC:
P P

C P C P C

P P

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

Phase1 Phase2
DistributedLocking:
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
itis exclusively locked. No two transactions can hold exclusive locks on same
recordat the same time. Any number of transactions can be able to achieve shared
lockson 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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|73
Distributedtwophaselocking:
Two phase locking is a process used to gain ownership of shared resources
without creating the possibility of deadlock.
Thereare3activitiesthattakeplaceinthetwophaseupdatealgorithm:
1. Lockacquisition
2. Modificationofdata
3. ReleaseLocks
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
releasingallresourcesithasacquired.Thismeansthatnoprocessisinastate 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
tryto 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.
Timestamping:
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|74
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.
Timestampbasedconcurrencycontrolprotocolscanbeusedindistributedsystems.
➢ Eachtransactionmustbegivenauniquetimestamp.
➢ Mainproblem:howtogenerateatimestampindistributedmanner.
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.

Localunique site
timestamp identifier

Globaluniqueidentifier

➢ Asitewithaslowclockwillassignsmallertimestamps.
o Stilllogicallycorrect:serializabilitynotaffected
o But:“disadvantages”transactions
➢ Tofixthisproblem
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 Inthiscase,siteSiadvancesitslogicalclocktothevaluex+1.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|75
CLIENTSERVERSYSTEMS:
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
performbusinessfunctions.Ifthebusinessfunctionsresideontheserver,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.
Theadvantagesofusingaclient/serversysteminsteadofafileserverare:
 Lowernetworktraffic
 Improvedprocessingdistribution
 Thinnerclients
 Greaterprocessingtransparency
 Increasednetwork
 Hardwareandsoftwaretransparency

RELATIONALDATABASEMANNGEMENTSYSTEM Page|76
 Improvedsecurity
 Decreasedcostsandincreasedscalability

Client3
Client1 Client2

NETWORK

Server

CLIENT/SERVERDATABASESYSTEMS:
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|77
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.
Clientcomputer Clientcomputer

SQLServerClient SQLServerClient
Application Application

Databasecomputer

SQL Server SQLServerClient


Application

Internetserver

Server Internet
Application InformationServer

Internetclients

RELATIONALDATABASEMANNGEMENTSYSTEM Page|78
Advantagesofstoringthedataintheserver:
 Eachdata itemisstoredinacentrallocationwhereall users canwork with it.
 Business and security rules can be defined one time on the server
andenforced equally among all users.
 Hardwarecostscanbeminimizedbecausethedataisnotstoredon each client.
Clients do not want to give space for storing data.
 TheservercanbeconfiguredtooptimizethediskI/Ocapacities.
 Theservercanbestoredinasecurelocationandequippedwith devices.
 Maintenancetaskssuchasbackingupandrestoringdataare simplified.
ClassicClient/ServerArchitecture:
Clientmachines:-
o Runowncopyofoperatingsystem.
o Runoneormoreapplicationsusingclient’sCPU&memory.
o ApplicationcommunicateswithDBMSserverrunningonservermachine through a
Database Driver.
o Examples:PCswithMSwindowsoperatingsystem
Servermachines:-
o Runowncopyofoperatingsystem.
o RunaDBMSthatmanagesadatabase.
o AcceptsconnectionsfromclientmachinesandsubmitstransactionstoDBMS.
o Examples:RDBMSsuchasOracleServer,Sybase,DB2etc.
Middleware:-
o Smallportionofsoftwarethatsitsbetweenclientandserver.
o Establishesaconnectionfromtheclienttotheserverandpassescommands.
o Examples:Sybaseopenclientandopenserver,Clientapplicationenablers.
Businessrulesmaybeenforcedat:
o Theclientapplicationcalled“FatClients”
o Entirelyonthedatabaseservercalled“ThinClients”
o Amixofboth.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|79
AdvantagesofClient/Server:-
1. Processingoftheentiredatabaseisspreadoverclientsandserver.
2. DBMScanachievehighperformance.
3. Clientapplicationscantakefulladvantageofadvanceduserinterfaces.
DisadvantagesofClient/Server:-
1. Implementationismorecomplex.
2. Itispossiblethatnetworkisnotwellsuitedforclient/servercommunications.
3. AdditionalloadonDBMSservertohandleconcurrencycontrol.

NeedforClientServerComputing:
Client/Server computing is a computing model in which client and server
computerscommunicate witheachotheroveranetwork.Inclient/servercomputing, 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. Remotepresentation:Theclienthandlesorcontrolstheentirepresentation
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.

RELATIONALDATABASEMANNGEMENTSYSTEM Page|80

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy