Professional Documents
Culture Documents
UNIDAD III
TRANSACCIONES EN LAS BASES DE
DATOS
Contenido
Procesamiento de Transacciones.
Conceptos de transacciones.
Propiedades de las Transacciones.
Planes y recuperabilidad.
Seriabilidad de los Planes.
Transacciones en SQL.
UTNeza Acad. BD
Procesamiento de Transacciones.
La Administracin de las Transacciones tiene como objetivo
llevar el control para la recuperacin y la concurrencia que
estn relacionadas con la cuestin general de la proteccin de
los datos; es decir, la proteccin contra la prdida o dao de la
informacin que est en la base de datos. En particular tienen
que ver con problemas como:
El sistema puede abortar cuando estn ejecutando algn programa,
UTNeza Acad. BD
Conceptos de transacciones
Una transaccin en una unidad de trabajo lgica. Considerndose
UTNeza Acad. BD
UTNeza Acad. BD
Overview
User
process
Instance
SGA
Data buffer
cache
Server
process
PGA
Redo log
buffer
Shared pool
Library
cache
Data dict.
cache
Parameter
file
Data
files
Control
files
LGWR Others
Redo
log files
Archived
log files
Password
file
UTNeza Acad. BD
Database
Base de Datos para Aplicaciones - PJGA
3
5
UTNeza Acad. BD
Bitcora de transacciones
UTNeza Acad. BD
Recuperacin de transacciones
UTNeza Acad. BD
Database Transactions
A database transaction consists of one of the
following:
DML statements which constitute one consistent change to
the data
One DDL statement
One DCL statement
UTNeza Acad. BD
10
Transacciones en SQL
UTNeza Acad. BD
11
Database Transactions
Begin when the first DML SQL statement is executed
End with one of the following events:
UTNeza Acad. BD
12
Advantages of COMMIT
and ROLLBACK Statements
With COMMIT and ROLLBACK statements, you can:
Ensure data consistency
Preview data changes before making changes permanent
Group logically related operations
UTNeza Acad. BD
13
Controlling Transactions
Time
COMMIT
Transaction
DELETE
SAVEPOINT A
INSERT
UPDATE
SAVEPOINT B
INSERT
UTNeza Acad. BD
ROLLBACK
to SAVEPOINT B
ROLLBACK
to SAVEPOINT A
ROLLBACK
14
COMMIT Processing
Instance
SGA
1
Server
process
Shared pool
LGWR
2
Data
files
Control Redo
files log files
User
process
Database
UTNeza Acad. BD
15
SAVEPOINT statement.
Roll back to that marker by using the ROLLBACK TO
SAVEPOINT statement.
UPDATE...
SAVEPOINT update_done;
Savepoint created.
INSERT...
ROLLBACK TO update_done;
Rollback complete.
UTNeza Acad. BD
16
Rollback Segment
Old image
New
image
Table
Rollback segment
DML statement
UTNeza Acad. BD
17
circumstances:
UTNeza Acad. BD
18
current user.
The affected rows are locked; other users cannot change the data
within the affected rows.
UTNeza Acad. BD
19
UTNeza Acad. BD
20
10
Committing Data
Make the changes.
DELETE FROM employees
WHERE employee_id = 99999;
1 row deleted.
INSERT INTO departments
VALUES (290, 'Corporate Tax', NULL, 1700);
1 row inserted.
Commit the changes.
COMMIT;
Commit complete.
UTNeza Acad. BD
21
UTNeza Acad. BD
22
11
Statement-Level Rollback
If a single DML statement fails during execution, only that
UTNeza Acad. BD
23
Read Consistency
Read consistency guarantees a consistent view of the data
at all times.
Changes made by one user do not conflict with changes
made by another user.
Read consistency ensures that on the same data:
UTNeza Acad. BD
24
12
UPDATE employees
SET
salary = 7000
WHERE last_name = 'Goyal';
Rollback
segments
changed
and
unchanged
data
before
change
old data
SELECT *
FROM userA.employees; Read
consistent
image
User B
UTNeza Acad. BD
25
Time
t1
t2
24000
t3
Session 1
Session 2
t4
34000
t5
UTNeza Acad. BD
COMMIT;
SELECT salary FROM employees
WHERE last_name='King';
26
13
Locking
In an Oracle database, locks:
Prevent destructive interaction between concurrent
transactions
Require no user action
Automatically use the lowest level of restrictiveness
Are held for the duration of the transaction
Are of two types: explicit locking and implicit locking
UTNeza Acad. BD
27
Implicit Locking
Two lock modes:
UTNeza Acad. BD
28
14
Bibliografia
Date C. J.
SISTEMAS DE BASES DE DATOS (VOLUMEN I).
Quinta Edicin.
Addison Wesley.
Shkuntala Atre.
TCNICAS DE BASES DE DATOS. ESTRUCTURACIN EN DISEO Y ADMINISTRACIN.
Trillas, 1991.
Nelson T. Dinerstein.
SISTEMAS DE MANEJOS DE ARCHIVOS Y BASES DE DATOS PARA MICROCOMPUTADORAS.
CECSA, 1990.
Rose Deakin.
BASES DE DATOS. USO Y ADMINISTRACIN EN CENTROS DE COMPUTO.
Trillas, 1988.
Korth., Silberschatz, Sudarshan
FUNDAMENTOS DE BASES DE DATOS.01
McGrawHill, 4ta. Edicin, Mexico, 2002
Adad Ruben, Medina Miguel A. y Careaga Alfredo.
FUNDAMENTOS DE LAS ESTRUCTURAS DE DATOS RELACIONALES.
Megabyte. Noriega Editores, 1992.
Cesar Perez Lopez
ORACLE 9I, ADMINISTRACIN Y ANLISIS DE BASE DE DATOS
Ed. Alfaomega RaMa, Mxico, 2003
Cesar Perez Lopez
ORACLE 9I / SERVIDOR DE APLICACIONES RED Y PROGRAMACION
Ed. Alfaomega RaMa, Mxico, 2003
Michael Abbey, Mike Corey, Ian Abramson
ORACLE 9i , GUIA DE APRENDISAJE
Mc Graw Hill- Osborne, Oracle Press, Mexico, 2002
Javier Lopez H.
ORACLE, FUNDAMENTOS PARA EL DESARROLLO DE APLICACIONES WEB
Coleccin USERS-libros.tectimes.com
MP Ediciones Bs. As.-Argentina
Paul Dorsey, Joseph R. Hudicka
ORACLE 8, DISEO DE BASES DE DATOS CON UML
Oracle Press- McGrawHill, Mexico, 1999
UTNeza Acad. BD
29
15