94 (0.00 50€)
inset (04
al
» Agaregate Functions
1
posueon
{mum etc.
ecimes for decision making we need summarize data from table like average, sum, mini
somé
operates on
squ provides various aggregate functions which can summarize data of given table. The function os
data produces a single output.
such queries are generally used for producing reports and summary forms in an application
7121 Types of Aggregate Functions
4) COUNT ({DISTINCT] €) : The number of (unique) values in the column C.
») SUM ({DISTINCT] €) : The sum of all (unique) values in the column C.
|) AVG ({DISTINCT] C) : The average of all (unique) values in the column C.
4 MIN (C): The minimum value in the column C.
¢) MAX (©) : The maximum value in the column C.7.12.1(A) COUNT()
. ted by query.
* This function is used to calculate number of rows (or records) in a table selected by query.
is not NULL.
* COUNT returns the number of rows in the table when the column value is not
Example
‘Table 7.12.1: Exam Marks
ry SName | Marks
rons ah] Mahesh 90
Boge tect a le
tt jyendra 89
4 Sachin a 99
3 Vishal Ae
ian g Payal 90
Column in the query must be numeric.
Find total number of students in Table 7.12.1.
COUNT
Let us consider above table modified as follows,
(Some duplicate rows are present in Table 7.12.2).
Table 7.12.2
sid SName Marks
1__| Mahesh 90
1__| Mahesh 90
2 | suhas 80
3__|Jyendra 89
3_| Jyendra 89
Sachin
Vishal
Payalowe can Ody Query ag
poole ‘
a number of dif
pot ereN students
spuecr CountDistinet Sd) ag gg 2PM Table 7129,
proM Exam Marks; Rian '
2
112.4(8) SUMO) |
‘This function is used to calculate
‘Sum of
Column in the query must be numer: sim” Vales in a table selected by query.
fad otal of marks scored by all students,
SELECT SUM(Marks) as Sum 9
FROM Exam_Marks; .
7.12.1(C) AVG()
+ This function is used to calculate Average of column values in a table selected by query.
+ This function first calculates sum of column and then divide by total number ofrows.
+ AVG returns the average of all the values in the specified column.
* Column in the query must be numeric.
Eample
Find average marks of students.
SELECT A’
PROM
™2.1(0) MINO
This function is
Column inDBMS (MU-Sem4-Comp) _
cample
Find minimum marks scored by students.
SELECT MIN(Marks) as Min
FROM Exam Marks;
7.12.1(E) MAX()
* This function is used to find maximum value out of column values in a table selected by,
Column in the query need not be numeric data type
Example
Find maximum marks scored by students.
SELECT §MAX(Marks) as Max
FROM — Exam Marks;
| 80
7.12.1(F) Summary of Aggregate Functions8.1 Triggers
ran
@. Write short note on : Triggers CEST
L@._What is tigger 2 Write syntax and example.
1) Introduction
+ Atriggeris a procedure that is automatically invoked by the DBMS in response to specific alteration to the
database or a table in database.
* Triggers are stored in database as a simple database object.
* Adatabase that has a set of associated triggers is called an active database,
* A database trigger enables DBA (Database Administrators)
separate databases.t en ee
ecute when triggering CO”
Action (A) - This is code or statement that ex:
activated on database table.
3) Trigger syntax
CREATE [OR REPLACE] TRIGGER
[ENABLE | DISABLE>]
sINSERT | UPDATE | DELETE>
ON
[FOR EACH ROW]W DBMs (MU - Sem 4 -
DECLARE"+ Creating. trigger on employee table whenever new employee added a comment is written to
* Letus write a trigger and study its effect.
‘Example:
‘SQL> CREATE OR REPLACE TRIGGER AutoRecruit
2. AFTERINSERT ON EMP
FOREACH ROW
BEGIN
{Insert into EmpLog values (‘Employee Inserted’);
END;
Nan aeWY DEMS (MU - Sem 4- Comp) 9-6 Relational Database Design
1) Introduction
* Normalization is a step by step decomposition of complex records into simple records.
* Normalization is a process of organizing data in database in more efficient form. It results in tables that
satisfy some constraints and are represented ina simple manner.
This process is also called as canonical synthesis.
Normalization is a step by step decomposition and database designers may not normalize relation to the
highest possible normal form.
‘The relations may be left in a lower normal form like 2NF, which may cause some penalties like data
anomalies.
Definition : Normalization is a process of designing a consistent database by ‘minimizing redundaney
ensuring data integrity through decomposition which is lossless.
2) Goals of Database Normalization
1. Ensures data integrity.
2. Prevents redundancy in data.
3. To avoid data anomaly
(a) Update anomaly
(b) An insertion anomaly
(©) Deletion anomaly
9.4 Functional Dependencies
eit 2a
In above table candidate key is {Employee_1d, Project 1d)
+ Prime Attributes : Employee_Id, Project 1d
* Non-Prime Attributes : Ename, Salary, Hours, Allowance
9.10 Normal Forms
CMSA Co
| Q. Explain 1 NF, 2. NF and 3 NF with suitable example.
[.@.__ Explain the various normal forms with an example
Various types of Normal form are as follows :
1, First Normal Form (1NF)
Second Normal Form (2NF)
Third Normal Form (3NF)
Boyce-Codd Normal Form (BCNF)
2
3
4.
9.10.1 First Normal Form (1NF)
1) Introduction
*~ This is simplest form of normalization, simplifies each attribute in relation.
This normal form given by E.F. Codd (1970) and the later version by CJ. Date (2003).
om
Dein: heer ti te ate ind a an lr
tuple must have a single value from the domain of that attribute.Database Desig
‘exactly one value for each attribute.
bearable
” ee een recrcs
fi = Employee Table
1) Te seo Epler |
\ area onal schema is as given below
‘and it contains the Eeity which is non atomic
Table 9.10,
:{Non-Normalised) Employee Table
Employee td | Ename
Salary | Eeity
50000 | Mumbai, Pune
25000 | Mumbai
26000 | Pune
_18 Kasturi
©) Tocomer relational shaman FS
pies
50000 | Mumbai, Delhi
city attribute is divided in atomic domains it may introduce some
‘Table 9.10.2 : INF Employee Table
Employee.td | Ename | satary | Ecity
10 __| Mahesh | s0000 | Mumbai
10 __| Mahesh | 50000 | Pune
12 Suresh | 25000 | Mumbai
15, Ganesh | 26000 | Pune
18 Kasturi | 50000 | Mumbai
18 Kasturi | 50000 | Delhi
3) Minimizing Domain Redundancy
+ The first normal for will solve the group redundancy occurs in domain value as it allows only a single value
from the domain of that attribute.
+ So, INF will solve all problems related to domain redundancy.
ais slation in 1 NF,
+ Nested relations must be remaved to converte
8.10.2 Second Normal Form (2NF)
; °
aa ‘use of fll functional dependency and tries to remove problem of redundant data
* This normal form makes
Introduced by INF decomposition.
+ Thismormal form is given by EF. Codd in 1971+ Inshort 2NF mew
* There should not be wny partial dependency on primary key attributes.
© Consider
+ The relational schema not in 2 NF is represented as,
* As attributes Hours, Allowance of employee table are full functionally dependent on
* The state of Employee relational schema is, st
(MU Sem 4 Comp.)
£
1 ANE, afin INP ond all non key attributes in relation are filly funetionally Bopendent og
A relat
the primary key of the relation
on .
+ Arrelation tn in 2NF, If it ts in INF and every non key aad fully bare 2
complete primary key of relation (and not depends on part of (partial) primary
J ahould be in IN,
ample
ble with columns as shown in Table 9.10.4,
‘employs
Consider an Fimployee table with following PDs,
Employee.td > Ename, Salary
Employee.td, Project.1d > Hours, Allowance
As
{Employee td, Project 1d) -» Ename, Salary, Hours, Allowance
‘Therefore,
Candidate key (Employee. ld, Project.1d) is selected as primary key.
‘teributes Ename and Salary are partially depends on primary Key (As Ename, Salary
of primary key) osDBMS (MU Relational Database Desif
p————_Table 9.104: 2NF Employes Table
Employee 2
Suresh
Ganesh
Mahesh
Project (Employee 1d, Project ld, Hours,
i Allowance)
Employee Id, Project 1d Hours, All
lowance
Table 9.10.5 : 2NF Project Table
Employee td | Project.td | Hours | Allowance
10 E001 | 44 | 40000
2 Boss | 31 | 30000
15 ce71_| 23 | 20000
18 E002 | 12 | 15000
1s E001 | 24 | 20000
18 Boss | 11 | 10000
* Consider, Relation R(A, B,C, D,E,F) and the FDs as below,
ABC, BDC, DEF
{The candidate Key is {AD} — {A,D, B,C, F) selected as primary key.
All attributes are partially dependent on primary key.
Hence, Relation R is not in 2NF,
ii) The 2NF Relation Schema is,
Ri (A.B, C, D) with FDs A> BC, B—> DC
R2 (DE, F) with FDs D> EF
Minimizing Tuple Redundancy
* The second normal form will avoid same tuples to be repeated in a table as it fo
‘must be full functionally depends on primary key ofa relation.
+ 2NF will create a new table for each partial Key with all ts dependent attributes,
ces all non-key attributes
y EF. Codd in 1971,
dito minimize the transitive redundancy.DBMS (MU Sem 4 - Comp)
2) Definition
+ Arelation is in 3NF;ifitis in 2NF and all non-prime attributes ofthe relation are non-transii deen,
‘onthe every key.
‘* Arelation Ris in 3NF ifall non prime attributes are,
1. Full functionally dependent on primary key. “9
2. Non-transitive dependent on every key.
‘+ Arelational schema R is in 3NF, if non-trivial functional dependency XA holds true where X is,
and A is a prime attribute.
3) Example
* Consider an employee table with columns as shown in Table 9.10.6,
‘* The relational schema not in 2 NF is represented as,
‘* Consider an Employee table with following FDs,
Employee _Id—> Ename, Salary, Department Id
Department _Id— Dname
‘The state of Employee relational is,
Table 9.10.6 : Employee Table
Employee id | Ename | Salary | Department Id.
10 Mahesh | 50000 ci
12 Suresh | 25000 Ez HR
15 Ganesh | 26000 C1 IT
18 Mahesh | 50000 E2
{Employee_Id) —> Ename, Salary, Department.1d, Dname
Therefore,
Candidate key (Employee Id) is selected as primary key.
‘+ Asall attributes in employee table are fll funct
ee functionally dependent on primary key,jaws (MU-Sem 4 Comp)
ers D. $23 Relational Database Design
Employee Id Dname name)
Table 9.19.9.
= SNF Department Table
‘dependenton primary key.
+ Hence, Relation R is in 2NF, a ts
+ But,non-prime attributes B, D, EandF
+ So, Relation R is not in 3NR,
NF Relation Schema is,‘DBMS (MU - Sem 4- Comp)
ER. Codd in 1974
BCNF is always in 3NF-
es not satisfactorily handle the,
‘+ This normal form s governed by Raymond F. Boyce and
‘+ BCNFis more rigorous form of 3NF and every relation in
«The intention of Boyce-Codl Normal Form (BCNF) is that 3NF do
overlapping candidate keys. jee
‘ «transitivity is present in prime attributes of relation may not be remove yy NF.
2). Definitions 4
«© Arelation Ris said to be in BONF, ifand only ifevery determinant isa oe ne ‘nl
le
‘relational schema isn BCNF, if nontrivial functional dependeney X-?A :
relation R. ane
© In3NF definition A should be prime attribute, which s not the casein BCNF de ”
3) Example
~~ 6 Consider an employee table in which empl
«+ Therelatonal schema notin 2 NF is represented a, o
+ Consideran Employee table wit following FDS,
Employee. Id —> Ename Salary, Department Id
lyee can work in more than one department, —
Department ld > Dname
+ Thestate of Employee relational is,
‘Table 9.10.10 : Employee Table
Employee _Id | Ename | Department_Id | Dname
10 [Mahesh c1 1v_| Technical]
12_|Ganesh| 2 HR | skill
12 [Ganesh 1 it [Technical]
10 [Mahesh] 2 wr | skin
13 _| Satish EL 1s [te
Employee Id—» Ename
Department Id —> Dname, Dtype
Therefore,
* Candidate key (Employee_ld, Department Id) is selected as primary’
‘As no attribute in employee table is full functionally. dependent on pi
‘not in 2NF. All non-prime attrib
rai ute are non-transitively.
‘Tonormalize above schema to BCNF we can d
Employee (Employee id, Ename)ss (MU-Sem 4 Comp)
base Desten The determinant ployee 3S 9.25 vette algal
"didate key
Table 9.20,
case of
+ Department ( Dame Bop
Department Id — Dname, Diype
key of . ‘deerme Debate ea
Table 9.10.12: 3NF Department Table
[Department Dname | Dtype
a i _| Technical
F2 wR | skin
EL TS __| Technical
* Emp_Dept (Employee Id, Department Id)
Table 9.10.13 : 3NF Emp Dept Table
Employee td | Department.ta
10 ct
12 Ee
2 ct
to F2
13 EL
“Sang Key Tran (Key reaundene) to make all determinants as key of relation,
‘ ‘each functional dependency
CN will produces a table for Sapte TOs vara
. transitive
‘VF will create a new table for each
5 Fourth Normal Form (4 NF) oa| Concurrency Control: Lock:based, Timestamp-based prctocols. |
11.1_Concept of Concurrency Control
* _ Inasingle user database only one user is accessing the data at any time
* This means that the DBMS does not have to be corcerned with how changes made to the database will afer
other users,
ma multi-user database many users may be accessing the data at the same time. The operations of one user may
interfere with other users of the database
The DBMS uses concurrency control to manage multé-user databases,
Concurrency control is concerned with preventing loss of data integrity due to interference between users ina
‘multi-user environment.
Central Computer
wef dat
Terminals:
:
:
Fig. 11.1.1: Concurrent database access :
* Concurrency control should Brovidgalmaechanism for avoiding and managing conflict between vartous databast |
users operating same data item at same time. ;
11.2 Conflicting TransactionsIMS (MU- Sem 4 -Comp,)
Q. Write note on : Timestamp based Protocol.
1) Introduction
* To achieve serializabilty order of transactions for execution can be decided in advance using its
Which transaction entered in system,
* Ageneral method to achieve this is using time stamp ordering protocol,
2) Concept of Timestamp
‘xed timestamp is assigned at start of execution of the transaction, Every transaction has
a timestamp by database system denoted as S (1).
A transaction which has entered in sys
tem recently will have greater timestamp. lft
T; then,
TS(T)
‘+ Every data item X ts with two timestamp vahues :
a) W-timestamp (X)
* _ Itdenotes the largest timestamp of any transaction that executed: WRITE (X) succ
x
That mean itis timestamp of recent WRITE (X) operation, -
* On execution of next WRITE (X) operation (0,), W-timestamps will be
TS (0).
b) R-timestamp (Xx)
Denotes the largest timestamp of any transaction that executed RE
‘That mean itis timestamp of recent READ (X) operation,
‘On execution of next READ (X) operation (03), R
15 (0)).SZ DBMS (MU- Sem 4~Comp)
11s
W- timestamp (x)
a os
Concurrency Control
149 (Recent Write)
Operations
TS (1)
AE
‘That means, each transaction {s unaware of other transactions executing in the system simultaneously.
Example : Money transfer in above example. :
‘The database is temporarily inconsistent while above transaction is executing, with the deducted total y
‘ccount B. If some other concurrently runnit
4)Me permanently, although there is any type of failure after the transaction completes execution,
10.3 Transaction States
[ 2 & =o)
Q.__Write note on : Transaction state diagram.
1) Introduction
* _ Htransaction complete successfully it may be saved on to database server called as committed transaction
A committed transaction transfers database from one consistent state to other consistent state, which mus
persist even if there is a system failure.
‘Transaction may not always complete its execution successfully. Such a transaction must be aborted.
An aborted transaction must not have any change that the aborted transaction made to the database. Such
changes must be undone or rolled back.
* Once a transaction is committed, we cannot undo its effects by aborting it.
2) Transaction states
A transaction must be in one of the following states =Fig. 10.3.1 : State diagram of a transaction
3} Active
+ This is initial state of transaction execution.
+ Assoon as transaction execution starts itis in active state
+ Transaction remains in this state till transact
shes.
b) Partially committed
+ Assoon as last operation in transaction is executed transaction goes to partially committed state,
+ Atthis condition the transaction has completed its execution and ready to commit on database server. But
itis still possible that it may be aborted, as the actual output may be there in main memory, and thus a
hardware failure may prohibit its successful completion.
Failed
‘transaction enters the failed state after the system determines that the transaetion can no longer proceed with
its normal execution,
Example : In case of Hardware or logical errors occurs while execution.
@) Aborted
s Failed transaction must be rolled back. Then, it enters the aborted state,
«Transaction has been rolled back restoring into prior state,
‘+ Inthis stage system have two options :
1) Restart the transaction : A restarted transaction is considered to be a new transaction which may
recover from possible failure.
2) Kill the transaction : Because the bad input or because the desired data were not preseht in the
database an error can occurs. In this case we can kill transaction to recover from failure.
®) Committed
When last data item is writen out, the transaction enters into the committed state,
‘This state occurs after successful completion of transaction,
«A transaction is said to have terminated ifhas either committed or aborted.
10.4 Transaction Control Language/Commands (TCL)1) Introduction
+ Any SQL query can be executed with two basic operations on the database objects :
© Read
© Write k
* After executing SQL query we must specify its final action as commit (save data) 0
changes).
‘The COMMIT statement ends the operations and makes all chan,
successful completion.
* ABORT terminates and undoes all the actions done so far.
iges made
2) Commit Transaction
* A query that is successful and has encountered no errors is comn
changes to the database are made permanent and become visible to other
The syntaxiis as follows :
‘COMMIT [WORK] ile
+ The keyword WORK is not required, though it might be added
that is required.
COMMIT [ TRAN [ SACTION ] [transaction
‘+ As you can see, only COMMIT is required, eve I
(ie, TRAN instead of TRANSACTION). Alternatively COMM
3) Rollback Transaction
‘* A query that is unsuccessful and has enco
changes to the database are undone and the
+ Transaction-processing systems ensure
as it is modified, then using these“Peration performed by the transaction T on object X
Wr0X) : Denote P by the tral T
on object X
Serial Exec
410.6 Xecutions / Transactions / Schedules
troduction
»
model in which transactions that means after finishing first
executed in a serial orde
arts its execution.
vinmeatth sPeciies frst my transaction, then your tansaction other transactions should not see
2) Example
ler below two transactions Ty and Ty
* Transaction Ty : deposits Rs.100 to both accounts A and B.
* Transaction Tz doubles the balance efaccounts A and i
Ti: | Reaa(ay Tz: [Read(a)
ACA+ 100 [acaz
Write(A) |
| Reaa(s) | Read(s) |
BeB+ 100 BoB
[ Waites) Write(B)
Serial schedule for above transaction can be represented as follows,
Schedule A : A consistent serial schedule
onsistent serial schedule is obtained by executing T, right after T,
1 2 A B Operations
| F 25 25 [initial Balance
|Read(Aa); A A*2
|Write(A) 50 25 |
| Read(B); B<—Be2
| Write(B) 50 50
Read(A); A A+ 100
Write(A) | 140k a
Read(B); BB + 100DBMS (MU - Sem 4- Comp.)
10-10
Transaction
Im above Serial schedule for we can first execute transaction T, then T which may results in some final yvalyge==
Representation: — T; > T,
Schedule B : A consistent serial schedule
Aserial schedule that is also consistent is obtained by executing T2 right after Ty.
T Tz A B Operations
g 25 (|25__| Initial Balance
Read(A); AA +100
Write(a) 125 |25
Read(B); B<— B+ 100
Write(B) 25 [125
Real);
ACA
Write(A) [250 |125
Read(B);
Bap
writes) [250 [250
250 [250 [Final Balance
Representation : T,—>T;
In above schedule T; is executed entirely then Tz has started. Assume account A with Rs.25 and B with RS25
Then transaction T; will update A as 125 and Bas 125. Now T, will read updated values of A and B. T will
update value of A as 250 and B as 250, The consistency constraint is A+ B should remain unchanged. Sot ene!
Te,
A+B.
Le. 250 + 250 = 500 remains unchanged so execution of this schedule keeps database in consistent state
10.7 Concurrent Executions / Transactions / Scheduyie<ie. 250 + 250 = 500 remains unchanged so execution of Nhs sehen
10.7
Pee ree
Concurrent Executions / Transactions / Schedules aa
——— ei $$
1) Introduction
2) Advantages of concurrency
dD
‘Transactions executed concurrently, that means operating system executes one transaction fOF Some tag
then context switches to second transaction and so on.
‘Transaction processing can allows multiple transactions to be executed simultaneously on database server
‘Allowing multiple transactions to change data in database concurrently causes several complications wig
consistency of the data in database.
Ie was very simple to maintain consistency in case of serial execution as compare to concurrent execution af
transactions.
Improved throughput
+ Throughput of transaction is defined as the number of transactions executed in a given amount
+ _If we are executing multiple transactions simultaneously that may increase throughput a‘Transaction
Resource utilization det
lon defined a the processor and disk performing useful work oF NOE
eases.
The processor :
and disk uiization increase as number of concurrent transactions nC
ii) Reduced waiting time
tem.
wsaction C0
There ma
: sere may be some small transaction and some long transactions may be executing 0” syst
© ftransa
ae an vena unig serialya short transaction may have wo wai for 8 earlier long (ran
plete, which can lead to random delays in running a transaction
3) Example
Consider below two transactions and T;
he
Transaction Ty : Deposits Rs.100 to both accounts A and B.
Ty: [Ready |
Ae As 100
psccazes
[ weet)
Read)
BeBe 100,
[writes —_|
‘Transaction Tz : doubles the balance of accounts A and B.
Ta:
Read(®)
Beez |
[Write(@)
‘Above transaction can be executed concurrently as below,
Schedule C: A schedule that is not serial but is still consistent
leaving the actions of T; with those of T
Table 10.7.4
25
25_| initial Balance]
Read(A); AC A+ 100: ‘
Write(A}:
Obtained by inter
Read(A):A AY;
Write) 250)
Read(B); BB + 100;
Write(B) _|_|225)- 10.8 Serializability / Serializable Schedule
‘x
Explain the concept of Sorializabiity with its types.
* | The database system must control above concurrent execution of transactions serializability will ensure thatthe
database state remains in consistent state.
* Weirst need to understand which schedules will eisure consistency, and which schedules will not
* Asschedule is the actual execution sequence of concurrent transactions,
A schedule of two transactions T; and Ts ‘serializable’ ifand only if executing this schedule has the same ec,
aS any serial schedule (either T; :T, or T2:T}).
We consider only two operations: read and write for purpose of computational simplicity.
* Between a read (Q) instruction and a write (Q) instruction on a data item Q, a transaction may perform sequence
of operations on the copy of Q that s residing in the local buffer ofthe transaction,
* Thus the only important operations of a transaction from a scheduling point of view are its read and write
instructions,
hh
‘rious forms of schedule equivalence are:
1. Contict Serializabitty
i
Fig. 10.8.1: Serializablity schedule formBMS (MU -Sem 4 Comp
‘) introduction 10.13
‘The database system
remalnsin consistent state 2"! concur
state, ‘ent execution of transactions which ensure that the database state
2) Conflict
+ Apair of consecutive g
result of at least one of database actio
the transacting 2 WS) is in confic if changing their order would change the
St
‘Transaction Tj
g Read(D) | Write(D)
de Read(D) | No Conflict | Conflict
B | Write(o) | “connice | confice
6
+ Consider sche
+ schedule Shas two consecutive instructions and |, from transactions T, and T, respectively.
+ IF and 1, access to differer
nt data items then ot cond a
problem. they will not conflict and can be swapped, without any
+ Ifltand Ij access to same data item D then consider following consequences :
© i= READ (D), = READ (D) then no conflict as they only read value.
This operation is called as non conflicting swap,
© y= READ (D), l= WRITE (D) then they conflict and cannot be swapped.
°
‘© So we can say that instructions conflict if both consecutive instructions operate on same data item and from
different transactions and one of them is WRITE operation.
+ If | and J; access to different data item D then consider following all consequences no conflict as they
only read or writing different values.
+ 1, = READ (D)/WRITE (0), = READ (P) /WRITE (P) then no conflict as they only reading or writing
different data.
© The following set of actions is conflicting
Ty:ROO, TWO), T:WOD
+ While the following sets of actions are not:
T:ROD, TRO), T3R(X),
TEROO, TWO), TROD
3) Conflict equivalence
Two schedules are confit sna :DBMS (MU -Sem4- Comp.)
Table 10.8.1 : Schedule S
Ty Th
Read(P)
Write(P)
Read(P)
Read(Q)
Write(P)
Write(Q)
Read(Q)
Wite(Q) ‘
1 and READ(P) of T, cannot be swapped as they conflict,
* Instruction WRITE(P) of 1,
Table 10.8.2)
‘Table 10.8.2
a eae
Read(P)
Can not { Write(P)
BeSwap Read(P)
Read(Q)
Write(P)
Write(Q)
Read(Q)
Write()
wapped as they operate,
Instruction READ(Q) of T; and READ(P) of T, can be s
‘ot conflict (as shown in Table 10.8.3)
Table 10.8.3
1% Te
Read(P)Ee OO —
yu sem 4 Comp.)
on WRIE(Q) OFT nd WRT
* gpnatcanfice ot can be swapped a they operate on different data items 50
(eit!
eee (ir t
fee a
{___| | Reaacr)
we) Write)
Res
eM || | Reaaray
Read) Read(P)
Can be
Write(P) | | writecq)
swapped | | Write(q)
Write(P)
Read(Q) Read(Q)
Write(Q) Write(Q)
sruction WRITE (Q) of T; and READ (P) of Tz can be swapped as they operate on different data items so
ot conflict.
Table 10.85 : Schedule R
Ty T Th Th
Read(P) Read(P)
‘Write(P) ‘Write(P)
Read(Q) Read(Q)
canbe Swap Read(P) | | Write(Q)
‘Asno conflict {| Write(Q) Read(P)
Write(P) «| Write(P)
Read(Q) Read(Q
Write(Q), Write(Q
can transformed into schedule R as shown above which also
he schedule $ after performing swapping
1 same values of Pand Q.
ve schedule is same as serial schedule :Example
View equivalence is les strict than conflict equivalence, but is Wke conflict equivalence based on only the reag
and write operations of transactions.
Conditions for view equivalence
Let. D = Dataitem
SuSz = Transaction schedules
TT) = Database transaction
* Schedules 5; and Sz are view equivalent if they satisfy following conditions for each
4) 1 and Sz must have same transactions included and also they are performing:
data. IT reads initial value of D in Sy, then T, also reads initial value of D in Sa.
b) IFT) reads value of D written by 1) in S;. then T; also reads value of D written by Tj
©) IT) writes final value of D in Sy, then T, also writes final value of D im Sp.
First 2 conditions ensure that transaction reads same value in both schedules,
Condition 3 ensures that final consistent state.
If a concurrent schedule is view equivalent to a serial schedule of same
Serializable
Consider following schedule ; with concurrent transactions
{In both the schedules 5; and a serial schedule S; Ty reads
writes final value of D. So schedule S; satisfies all three conditions and is
Below two schedules $ and R are view equivalent,