[4] Transactions Flashcards

1
Q

Define a transaction.

A

A logical unit of work: either it completes as a whole or not at all.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following are transactions: DML, DDL?

A

Both DML(e.g. update) and DDL (e.g. create statements) are transactions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is ACID?

A

They are the properties of Transactions: Atomicity, Consistency, Isolation and Durability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe atomicity.

A

Every transaction is a unit of work: all succeed or none succeed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe consistency in transactions.

A

Transactions must result in maintaining a consistent state for the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe isolation in transactions.

A

One transaction’s changes must not affect the changes of another transaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe durability in transactions.

A

For interruptions in service, all committed transactions are rolled forward and all uncommitted are rolled back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does Commit and Rollback mean in T-SQL?

A

An approved transaction is committed. An unrecoverable error results in a rollback.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the 2 types of transactions.

A
  1. System: maintains internal persistent system tables (not user controlled).
  2. User: user-made to change/ read data.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Syntax to find transactions in the database

A

select distinct [name]

from sys.dm_tran_active_transactions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe the following transaction levels:

(a) @@TRANCOUNT = 0
(b) @@TRANCOUNT > 0
(c) @@TRANCOUNT > 1

A

a. 0 means code not within transaction.
b. > 0 means there is an active transaction.
c. > 1 indicates nested level of transaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe the following transaction states:

(a) XACT_STATE() = 0
(b) XACT_STATE() = 1
(c) XACT_STATE() = -1

A

(a) no active transaction.
(b) uncommited transaction that can be committed, but nested level not reported.
(c) uncommited transaction with fatal error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of the @@TRANCOUNT and XACT_STATE() syntaxes?

A

@@TRANCOUNT checks transaction nesting level and the XACT_STATE() reports (un)committed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the 3 transaction modes?

A
  1. Autocommit
  2. Implicit transaction
  3. Explicit transaction
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
The diagram below describes which type of transaction mode and how does it differ from the other modes?
                 \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
                 |  @@TRANCOUNT = 0    |
                 |\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_|
	                              |
	                              |
                   \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
                   |    Work = DDL/DML    |
                   |\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_|
	                              |
	                              |
A

Autocommit: there is no requirement for BEGIN TRAN, COMMIT TRAN, or ROLLBACK TRAN statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly