LearnFrenzy
Sign in Take a free test

DBMS & SQL · Topic 8 of 10

Transactions and Concurrency: questions with answers

ACID, COMMIT and ROLLBACK, savepoints, isolation levels and read anomalies, serializability, locking, deadlocks and recovery.

Questions
45
Timed sets
3
Queries executed
8
Your accuracy
–

What this topic covers

26 subtopics
  • Serializability5
  • ACID4
  • Isolation levels3
  • Read anomalies3
  • COMMIT2
  • Deadlock2
  • Locking2
  • Recoverability2
  • Recovery2
  • ROLLBACK2
  • Schedules2
  • Timestamp ordering2
Show all 26 subtopics
  • Autocommit1
  • Basics1
  • Concurrency anomalies1
  • Consistency1
  • Deadlock prevention1
  • Distributed transactions1
  • Durability1
  • Implicit commit1
  • Locking reads1
  • MVCC1
  • Optimistic locking1
  • Safe updates1
  • SAVEPOINT1
  • Transaction states1
  • Beginner 15
  • Intermediate 15
  • Advanced 15

About this topic

A transaction groups several operations into one unit that either completes fully or not at all. The ACID properties – Atomicity, Consistency, Isolation, Durability – describe what a database promises about transactions, and concurrency control decides how simultaneous transactions may interleave safely. Interviews ask about ROLLBACK behaviour, isolation levels and read anomalies; GATE asks about schedules, serializability, locking and recovery.

Free preview

Sample questions

Try each one first, then open the answer for the explanation and why the other options are wrong.

Question 1 ACID Beginner Practice

A money transfer debits one account and then the server crashes before crediting the other. Which ACID property guarantees the debit is undone?

Atomicity
Isolation
Durability
Consistency
Show answer and explanation
Correct answer A

Explanation

Atomicity means all of a transaction's changes happen or none do. On recovery, the incomplete transfer is rolled back using the log.

Why the other options are wrong

  • BIsolation is about concurrent transactions not interfering.
  • CDurability is about committed data surviving crashes.
  • DConsistency is about rules (constraints) holding before and after.
Question 2 Autocommit Beginner Practice Query executed

No transaction was started. What is Ravi's balance after the ROLLBACK?

accounts
idholderbalance
1Asha1000
2Ravi500
UPDATE accounts SET balance = 0 WHERE id = 2;
ROLLBACK;
SELECT balance FROM accounts WHERE id = 2;
balance
0
balance
NULL
balance
(no rows)
balance
500
Show answer and explanation
Correct answer A

Explanation

With autocommit on (the default in MySQL and MariaDB), each statement outside an explicit transaction commits immediately. The ROLLBACK has nothing to undo. Always START TRANSACTION before changes you may want to roll back.

Why the other options are wrong

  • BThe balance was set to 0, not NULL.
  • CThe row still exists.
  • DThe UPDATE was already committed.
Question 3 Implicit commit Intermediate Practice Query executed

How many accounts exist after this script?

accounts
idholderbalance
1Asha1000
2Ravi500
START TRANSACTION;
INSERT INTO accounts VALUES (3, 'Meena', 300);
CREATE TABLE audit_log (id INT);
ROLLBACK;
SELECT COUNT(*) AS n FROM accounts;
n
3
n
1
n
0
n
2
Show answer and explanation
Correct answer A

Explanation

In MySQL and MariaDB, DDL statements such as CREATE TABLE cause an implicit COMMIT. The INSERT was committed before the ROLLBACK ran, so Meena stays. (PostgreSQL supports transactional DDL and would roll both back.)

Why the other options are wrong

  • BNothing deleted accounts.
  • CThe original two accounts were never touched.
  • DThe CREATE TABLE committed the INSERT.
42 more questions in the timed setsSame format as the samples, with a timer, a question palette and a full review at the end.
Start practising

DBMS & SQL

All 10 topics

Topics, levels and full mocks
  1. 01 DBMS and SQL Fundamentals45 questions · 3 levels
  2. 02 Joins and Subqueries45 questions · 3 levels
  3. 03 Aggregates and GROUP BY45 questions · 3 levels
  4. 04 Window Functions45 questions · 3 levels
  5. 05 Keys and Constraints45 questions · 3 levels
  6. 06 ER Model and Relational Mapping45 questions · 3 levels
  7. 07 Normalization45 questions · 3 levels
  8. 08 Transactions and Concurrency45 questions · 3 levels
  9. 09 Indexing and Query Optimisation45 questions · 3 levels
  10. 10 Advanced SQL Queries45 questions · 3 levels

Search LearnFrenzy

Esc

Quick links