MCQs on Transactions and Concurrency | SQL Server

Discover essential concepts of Transaction Management, ACID properties, Locks, Isolation Levels, and Deadlocks. Enhance your SQL expertise with these 30 carefully designed MCQs for practical learning.


Transaction Management

  1. What is the purpose of a transaction in SQL Server?
    a) To execute multiple operations atomically
    b) To optimize performance
    c) To backup the database
    d) To create indexes
  2. Which command explicitly starts a transaction in SQL Server?
    a) START TRANSACTION
    b) BEGIN TRANSACTION
    c) TRANSACTION BEGIN
    d) INITIATE TRANSACTION
  3. What does the COMMIT statement do in a transaction?
    a) Rolls back all changes
    b) Saves all changes permanently
    c) Starts a new transaction
    d) Pauses the transaction
  4. What is the role of the ROLLBACK command in a transaction?
    a) Saves all changes made during the transaction
    b) Cancels all changes made during the transaction
    c) Ends the transaction with a commit
    d) Logs the transaction details
  5. Which statement is used to create intermediate checkpoints within a transaction?
    a) SAVEPOINT
    b) CHECKPOINT
    c) PAUSEPOINT
    d) STOPPOINT

ACID Properties

  1. Which ACID property ensures that a transaction’s changes are permanent once committed?
    a) Atomicity
    b) Consistency
    c) Isolation
    d) Durability
  2. What does the Atomicity property guarantee in transactions?
    a) All parts of a transaction are executed or none at all
    b) Transactions do not interfere with each other
    c) Database remains consistent
    d) Changes are permanently stored
  3. Which ACID property is related to maintaining database consistency?
    a) Isolation
    b) Atomicity
    c) Consistency
    d) Durability
  4. What does the Isolation property ensure?
    a) Transactions are committed independently
    b) Transactions are isolated from other concurrent transactions
    c) Transactions execute immediately
    d) Transaction results are stored temporarily
  5. Which ACID property ensures that committed transactions survive power failures?
    a) Consistency
    b) Durability
    c) Atomicity
    d) Isolation

Locks and Isolation Levels

  1. Which type of lock prevents any other transactions from accessing the locked resource?
    a) Shared lock
    b) Exclusive lock
    c) Intent lock
    d) Update lock
  2. What is the purpose of a shared lock in SQL Server?
    a) Allows read operations but no modifications
    b) Allows write operations but no reads
    c) Blocks all access to the resource
    d) Prevents deadlocks
  3. Which isolation level in SQL Server allows dirty reads?
    a) READ COMMITTED
    b) READ UNCOMMITTED
    c) SERIALIZABLE
    d) REPEATABLE READ
  4. What is the default isolation level in SQL Server?
    a) READ UNCOMMITTED
    b) READ COMMITTED
    c) SERIALIZABLE
    d) SNAPSHOT
  5. Which isolation level ensures no other transactions can access the locked data until the current transaction is complete?
    a) READ COMMITTED
    b) SERIALIZABLE
    c) REPEATABLE READ
    d) SNAPSHOT

Deadlocks and Troubleshooting

  1. What is a deadlock in SQL Server?
    a) A situation where two transactions wait on each other indefinitely
    b) A timeout error in a query
    c) A failure to acquire a lock
    d) A rollback due to an error
  2. Which SQL Server feature automatically resolves deadlocks?
    a) Deadlock Monitor
    b) Lock Manager
    c) Query Optimizer
    d) Transaction Handler
  3. How can deadlocks be minimized?
    a) By implementing proper indexing
    b) By ensuring consistent access order to resources
    c) By avoiding transactions
    d) By enabling dirty reads
  4. Which command provides information about active locks in SQL Server?
    a) DBCC INPUTBUFFER
    b) DBCC LOGINFO
    c) sp_lock
    d) sp_deadlockchain
  5. What happens when a transaction is involved in a deadlock?
    a) Both transactions are rolled back
    b) One transaction is chosen as a victim and rolled back
    c) Both transactions are committed
    d) Both transactions wait indefinitely

Mixed Topics

  1. What is the effect of the NOLOCK hint in SQL Server?
    a) Allows dirty reads
    b) Blocks all other transactions
    c) Ensures exclusive access
    d) Enforces consistent reads
  2. Which isolation level prevents phantom reads?
    a) READ UNCOMMITTED
    b) READ COMMITTED
    c) REPEATABLE READ
    d) SERIALIZABLE
  3. What is the main drawback of using the SERIALIZABLE isolation level?
    a) It allows dirty reads
    b) It uses more resources and reduces concurrency
    c) It does not guarantee consistency
    d) It cannot be used in transactions
  4. Which system stored procedure is used to monitor blocked transactions?
    a) sp_blockerstatus
    b) sp_lockinfo
    c) sp_blockinfo
    d) sp_monitorblock
  5. What is the effect of setting a transaction to READ UNCOMMITTED?
    a) Allows dirty reads
    b) Prevents phantom reads
    c) Ensures full isolation
    d) Disables locks
  6. What is the purpose of a deadlock priority in SQL Server?
    a) Determines which transaction to roll back during a deadlock
    b) Prevents deadlocks altogether
    c) Controls the order of lock acquisition
    d) Resolves blocking issues
  7. What happens when you execute a transaction without a COMMIT or ROLLBACK statement?
    a) The changes are held in a pending state
    b) The changes are automatically committed
    c) The transaction is rolled back
    d) Throws an error
  8. Which DMV (Dynamic Management View) provides details about currently executing transactions?
    a) sys.dm_tran_locks
    b) sys.dm_exec_requests
    c) sys.dm_tran_active_transactions
    d) sys.dm_exec_sessions
  9. Which SQL Server tool helps in analyzing deadlock graphs?
    a) SQL Profiler
    b) Database Engine Tuning Advisor
    c) Extended Events
    d) Activity Monitor
  10. Which command rolls back to a specific SAVEPOINT?
    a) ROLLBACK TO SAVEPOINT
    b) ROLLBACK SAVEPOINT
    c) SAVEPOINT TO ROLLBACK
    d) ROLLBACK TO

Answer Key

QnoAnswer
1a) To execute multiple operations atomically
2b) BEGIN TRANSACTION
3b) Saves all changes permanently
4b) Cancels all changes made during the transaction
5a) SAVEPOINT
6d) Durability
7a) All parts of a transaction are executed or none at all
8c) Consistency
9b) Transactions are isolated from other concurrent transactions
10b) Durability
11b) Exclusive lock
12a) Allows read operations but no modifications
13b) READ UNCOMMITTED
14b) READ COMMITTED
15b) SERIALIZABLE
16a) A situation where two transactions wait on each other indefinitely
17a) Deadlock Monitor
18b) By ensuring consistent access order to resources
19c) sp_lock
20b) One transaction is chosen as a victim and rolled back
21a) Allows dirty reads
22d) SERIALIZABLE
23b) It uses more resources and reduces concurrency
24a) sp_blockerstatus
25a) Allows dirty reads
26a) Determines which transaction to roll back during a deadlock
27a) The changes are held in a pending state
28c) sys.dm_tran_active_transactions
29c) Extended Events
30d) ROLLBACK TO

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top