database transaction
any (possibly multi-step) action that reads from and/or writes to a database
a database transaction may consist of
a single SQL statement or a collection of related SQL statements
successful transaction
all of the SQL statements are completed successfully
consistent database state
all data integrity constraints are satisfied
successful transaction changes the database from
one consistent state to another
improper or incomplete transactions can have a
devastating effect on database integrity
if a DBMS supports transaction management, it will
roll back an inconsistent database to a previous consistent state
an inconsistent database is the result of
an unsuccessful transaction
properties of a transaction
atomicity
consistency
isolation
durability
atomicity
the “all or nothing” property
- all transaction operations must be completed
- transaction is treated as a single unit of work
consistency
when a transaction is completed, the database must be in a consistent state
isolation
data used during the execution of a transaction cannot be used by a second transaction until the first one is completed
durability
once transaction changes are committed (applied to database), they cannot be undone or lost due to a subsequent failure
if a transaction involves reading from a table,
no changes are made to the database, and it remains in a consistent state
if a transaction requires updating two tables, the database is in ____ only if _____
a consistent state, both database requests are successfully completed
ANSI SQL standards for managing transactions:
COMMIT;
ROLLBACK;
BEGIN TRANSACTION also used by some DBMSs
COMMIT;
permanently records all changes in the database, automatically ends transaction
ROLLBACK;
aborts all uncommitted changes, database is rolled back to previous state
t/f: a rolled back transaction can typically be restarted later
true
a DBMS maintains a transaction log to
support recovery to a consistent state
transaction log stores
the transaction log record for a transaction component includes
transaction log is typically implemented as
one or more files that are stored separately from the database itself
t/f: a transaction log is automatically updated when the DBMS executes transactions
true