[4] Transactions Flashcards
Define a transaction.
A logical unit of work: either it completes as a whole or not at all.
Which of the following are transactions: DML, DDL?
Both DML(e.g. update) and DDL (e.g. create statements) are transactions.
What is ACID?
They are the properties of Transactions: Atomicity, Consistency, Isolation and Durability
Describe atomicity.
Every transaction is a unit of work: all succeed or none succeed.
Describe consistency in transactions.
Transactions must result in maintaining a consistent state for the database.
Describe isolation in transactions.
One transaction’s changes must not affect the changes of another transaction.
Describe durability in transactions.
For interruptions in service, all committed transactions are rolled forward and all uncommitted are rolled back.
What does Commit and Rollback mean in T-SQL?
An approved transaction is committed. An unrecoverable error results in a rollback.
Describe the 2 types of transactions.
- System: maintains internal persistent system tables (not user controlled).
- User: user-made to change/ read data.
Syntax to find transactions in the database
select distinct [name]
from sys.dm_tran_active_transactions
Describe the following transaction levels:
(a) @@TRANCOUNT = 0
(b) @@TRANCOUNT > 0
(c) @@TRANCOUNT > 1
a. 0 means code not within transaction.
b. > 0 means there is an active transaction.
c. > 1 indicates nested level of transaction.
Describe the following transaction states:
(a) XACT_STATE() = 0
(b) XACT_STATE() = 1
(c) XACT_STATE() = -1
(a) no active transaction.
(b) uncommited transaction that can be committed, but nested level not reported.
(c) uncommited transaction with fatal error.
What is the purpose of the @@TRANCOUNT and XACT_STATE() syntaxes?
@@TRANCOUNT checks transaction nesting level and the XACT_STATE() reports (un)committed.
What are the 3 transaction modes?
- Autocommit
- Implicit transaction
- Explicit transaction
The diagram below describes which type of transaction mode and how does it differ from the other modes? \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ | @@TRANCOUNT = 0 | |\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_| | | \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ | Work = DDL/DML | |\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_| | |
Autocommit: there is no requirement for BEGIN TRAN, COMMIT TRAN, or ROLLBACK TRAN statement.