0% found this document useful (0 votes)
5 views

DBMS 3

The document discusses transactions in databases. A transaction is a collection of database operations, such as inserts, updates or deletes, that must all succeed together to maintain data integrity. Transactions have the ACID properties - Atomicity, Consistency, Isolation, and Durability - to ensure reliability even in the presence of failures. The basic operations in a transaction are reads, writes to modify data, and commit or rollback to permanently save or undo the transaction's changes.

Uploaded by

Riya Choudhary
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)
5 views

DBMS 3

The document discusses transactions in databases. A transaction is a collection of database operations, such as inserts, updates or deletes, that must all succeed together to maintain data integrity. Transactions have the ACID properties - Atomicity, Consistency, Isolation, and Durability - to ensure reliability even in the presence of failures. The basic operations in a transaction are reads, writes to modify data, and commit or rollback to permanently save or undo the transaction's changes.

Uploaded by

Riya Choudhary
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/ 5

Intersect · Ora cle

-- -
-- p ame city
custom er _Id - ----
John New York

S,1rah London
'2
f~"bert Paris
:i

two result sets. The


■ The INTERSECT operator returns the common rows between
be the same in both
column names and data types of the corresponding columns must
SELECT statements.
J SELECT custom er_id, name , city
FROM Custo mers INTERSECT SELECT
customer_id, name, city FROM Orders;

Intersect · My SQ L
custom er _Id name
l city

John
J New York

london
2 '>.trah
1
h', ,t)e'"t ~ ,HIS
-l

n two result sets. The column names and


• The INTER SECT operato r returns the comm on rows betwee
both SELEC T statements.
data types of the corresp onding column s must be the same in
SELEC T custom er_ id, name, city FROM Customers
WHER E (custom er_ id, name, city) IN
(
SELEC T custom er_ id, name, city FROM Orders
):

EXCEPT (or MINUS):


s the rows from the
• Tbe EXCE PT opera tor (or MINU S in some databases) return
first result set that are not present in the secon d result set.
ns must be the
The colum n names and data types of the corre spond ing colum
same in both SELE CT statements.
SELE CT custo mer_id, name, city FROM Customers
EXCE PT
SELE CT custo mcr_ id, name , city FROM Orders;
-

name city
custome r _id
- - - . - -

t' ' r....,' '


..

'·' h.Jf'I ·~ H ~I I "


;;
Introduction to Transaction
lec tio n of ope rat ion s tha t fon n a single logica l unit of work
Transaction is a col g, or
of on e or mo re dat aba se op era tions, such as inserting, updatin
that consists
deleting data.
t and
des ign ed to ens ure tha t the database remains in a consisten
• Transactions are ltiple
te, eve n in the pre sen ce of fai lures or concurrent access by mu
reliable sta
users.
ned to
nsa cti on s are log ica l uni ts of work which must ALL be perfon
• Database tra
maintain dat a integrity.
ACID :
based on the principles known as
Th e con cep t of a transaction is
, and Durability.
Atomicity, Consistency, Isolation

--- - ---
Introduction to Transaction
• Examples
ount to another.
u Mo ney transfer from one acc o = 123 ;
DA TE Ac cou nt SE T bal anc e = balance - I00 WHERE AccN
UP ;
Ac cou nt SE T ba lan ce= bal ance + 100 WHERE AccNo = 124
UPDATE
□ Pu rch ase of an Item stock
ory ma nag em ent , it inv olv es creation of orders , decrease the
In invent
quantity, add ing payment, etc.

ion
B as ic Operations in a Transa. ct
Rea ds, Writes dat a item s .
X into program variable .
Rea d(X ) : Rea ds a data bas e item into the data base item X.
e of pro gra m vari able
: Wr ite( X) : Writes the valu
rt
• Spe cial actions: Com mit , Abo
· I . ·t
0
Com mit : 1og'.ca um . nnanently saved and become part of
• On suc cess ful completionnge of all the iru:~ ction as a pe
all the cha s mad e within the transact ion are
• It ens ures that .
the data base. res.
ble and can survive system failu
• Com mit ted data is made dura
all the instructions . .
0 . r.,ace s problems in complet ing
or Rol lba ck: sac tion whi ch transaction .
Ab ort . f · g tran d all the changes made within the
• Ten nin ano n o an ong oinlso known as roll bac k, un oes
. transaction began.
h d b e to its state before the
• Abo rtin g a tran sact ion, a dur ing the transac tion exe cution.
discards the cha nge s and reve rts t e ata as r. ·1ure s
• It
. d ·
10 s ons e to erro.rs or ,a, h committed to the database.
one re P .
• Abo rt is typ1caUy that no partial or mco ns1s tent c ang es are
• Rollback ens ures
4:30 ,111 5G 18 ·

Basic Requirements of Transaction


• A transaction must see a consistent database.
■ During transaction execution the database may be temporarily
inconsistent.
■ When the transaction completes successfully (is committed), the
database must be consistent.
■ After a transaction commits, the changes it has made to the database
persist, even if there are system failures.
• Multiple transactions can execute in parallel.

IAcID Properties
■ ACID is an Atomicity, Consistency, Isolation, and Durability.
• These properties are crucial for ensuring the reliability and integrity of
transactions in a database system must maintain.

■ Atomicity:
::J Atomicity guarantees that a transaction is treated as a single, indivisible unit

of work.
'.J Either all the operations within a transaction are successfully completed and
committed, or none of them are.
□ If any part of the transaction fails, all the changes made by that transaction
are rolled back, ensuring that the database remains in a consistent state.

ACID Properties
■ Consistency:
□ Consistency ensures that a transaction brings the database from one valid state to
another.
□ The database must satisfy certain integrity constraints before and after the transaction.
□ In other words, a transaction should preserve the overall correctness and validity of
the data.
■ Isolation:
u Isolation ensures that concurrent transactions do not interfere with each other.
□ Each transaction should be executed as if it were the only transaction running on the
system.
□ Isolation prevents issues such as dirty reads, non-repeatable reads, and phantom reads.
u lt provides a level of separation between transactions to maintain data integrity and
prevent data inconsistencies.
4:30 ,111 5G 18 '

ACID Properties
■ Durability:
:::i Durability guarantees that once a transaction is committed, its changes
are permanent and will survive any subsequent system failures, such as
power outages or crashes.
'.J The committed data is stored in non-volatile storage (usually disk) and
can be recovered even in the event of a system failure.

Example Transaction
■ Transfer Rs.SO from account A to account B. The transaction will look like the
follow;

Atomicity
Read(A)
shouldn't take money from A
A=A-50 without giving it to B
Write(A) Consistency
Read(B) money isn't lost or gained
B = 8+50 Isolati-on
Write(B) other queries shouldn't see A or
B change until completion
Durability
the money does not go back to
A

Transactions in Oracle
• Transactions can consist of one or more SQL commands.
• In Oracle, a transaction starts when you connect to sq/plus, and ends when you type
COMM IT ;
::i If you're accessing the database from 2 different applications, this explains what you've altered in
one application may not show up in the second.

• An implicit COMMIT occurs before and after any Data Definition commands
(CREATE, ALTER etc)

■ You can also use SET AUTOCOMM IT ON (or OFF) to force a commit after each
command.
Read(A) At om ic ity
A= A- 50 sh ou ldn 't ta ke mo ne y
fro m A
with ou t giv ing it to B
Write(A)
Co ns ist en cy
Read(B)
mo ne y isn 't los t or ga
B = 8+ 50 ined
Is ol at io n
Write(B)
ot he r qu er ies sh ou ldn
't see A or
B change un til co mp let
ion
Du ra bi lit y
th e mo ne y does no t go
ba ck to
A

Transactions in Oracle
• Transactions ca n cons
ist of on e or more SQ L co m m an
ds.
(' ln Or ac le, a transactio
n starts when yo u co nn ec
CO M M IT ; t to sq/plus , an d en ds wh
en yo u ty pe
.J If yo u'r e accessing the da
tabase from 2 different ap
on e applicat ion may no t sho plications, this explains wh
w up in the sec on d. at you' ve altered in
An implicit CO M MIT oc
cu rs before and after any
(C RE AT E, AL TE R etc) Da ta Definition co mm an
ds
• Yo u ca n also us e Sl 'T J\L
1 O( OM M IT O l\ (o r O
command. IT) to force a co mm it af
ter ea ch

IHow transactions are used?


Tr ansa ct io ns ar e us ed fo
r th re e pu rp os es in DB M
..J to de te rm in e
S:
wh en integrity constrai
of tra ns ac tio ns ) nt checks sh ou ld oc cu r (o
nl y at th e en d

:J to co nt ro l concurrent ac
cess. Gi ve s a singl e us er
us er of th e da ta base th e ill us io n of be in g th e
sole

.J to m an ag e recovery fro
m sy ste m cr as he s

You might also like