Transactions Flashcards
What is a transaction?
A transaction is a unit of work that might include multiple activities that query and modify data and that can also change the data definition.
What statement designates the beginning of a transaction?
BEGIN TRANSACTION;
What statement designates the end of a transaction?
COMMIT TRANSACTION;
What statement allows you to undo a transaction?
ROLLBACK TRAN or ROLLBACK TRANSACTION;
Which session option allows the user to change how SQL Server handles implicit transactions?
IMPLICIT_TRANSACTIONS (turned off by default)
List the four properties of a transaction.
atomicity, consistency, isolation, and durability (ACID)
Define atomicity in the context of a transaction.
Atomicity: a transaction is an atomic unit of work; either all changes in the transaction take place or none do.
Which session option will cause the encounter of any error, regardless if it is not severe enough to automatically trigger a rollback, to abort and rollback the transaction?
XACT_ABORT
Define consistency in the context of a transaction.
The term consistency refers to the state of the data that the relational database management system (RDBMS) gives you access to as concurrent transactions modify and query it.
Consistency also refers to the fact that the database must adhere to all integrity rules that have been defined within it by constraints (primary keys, unique constraints, etc.)
The transaction transitions the database from one consistent state to another.
Define isolation in the context of a transaction.
Isolation ensures that transactions access only consistent data.
You control what consistency means to your transactions though a mechanism called isolation levels.
describe the two models which SQL Server provides to handle isolation.
A model which uses locking (Default for SQL Server)
A model which uses a combination of locking and row versioning (Default for Azure SQL Database)
True or False:
In the model based on locking, readers require shared locks.
True:
If the current state of the data is inconsistent, readers are blocked until the state of the data becomes consistent.
True or False:
In the model based on a combination of locking and row versioning, readers require shared locks.
False:
In this model, readers don’t take shared locks and don’t need to wait.
If the state of the data is inconsistent, the reader gets an older consistent state.
Define durability in the context of a transaction.
Data changes are always written to the database’s transaction log on disk before they are written to the data portion of the database on disk.
After the commit instruction is recorded in the transaction log on disk, the transaction is considered durable even if the change hasn’t yet made it to the data portion on disk.
Describe lock in the context of a transaction.
Locks are control resources obtained by a transaction to guard data resources, preventing conflicting or incompatible access by other transactions.