Bird
Raised Fist0
DBMS Theoryknowledge~10 mins

Transaction states in DBMS Theory - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Transaction states
Start Transaction
↓
Active State
↓
Decision: Commit or Rollback?
↓
Partially Committed
↓
Committed
↓
End Transaction
A transaction starts active, then either commits or aborts, passing through intermediate states before ending.
Execution Sample
DBMS Theory
BEGIN TRANSACTION;
-- perform operations
COMMIT;
Starts a transaction, performs operations, then commits to save changes.
Analysis Table
StepTransaction StateActionResult
1StartBegin transactionTransaction is active
2ActivePerform operationsOperations executed
3ActiveDecide to commitMove to partially committed
4Partially CommittedCommit changesChanges saved, move to committed
5CommittedEnd transactionTransaction ends successfully
💡 Transaction ends after commit; all changes are saved permanently.
State Tracker
Transaction StateStartAfter Step 2After Step 3After Step 4Final
StateStartActivePartially CommittedCommittedEnd
Key Insights - 2 Insights
Why is there a 'Partially Committed' state before 'Committed'?
The 'Partially Committed' state means all operations are done but changes are not yet permanent; this is shown in execution_table step 3 and 4.
What happens if a failure occurs during the 'Active' state?
If failure occurs, the transaction moves to 'Failed' then 'Aborted' state, rolling back changes, which is not shown here but is a common alternate path.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the transaction state?
APartially Committed
BCommitted
CActive
DFailed
💡 Hint
Refer to the 'Transaction State' column at step 3 in execution_table.
At which step does the transaction end successfully?
AStep 5
BStep 2
CStep 3
DStep 4
💡 Hint
Check the 'Result' column for when the transaction ends in execution_table.
If the transaction fails during operations, which state would it enter next?
ACommitted
BAborted
CPartially Committed
DActive
💡 Hint
Recall the concept_flow shows failure leads to 'Aborted' state.
Concept Snapshot
Transaction states flow from Start -> Active -> (Commit or Rollback) -> End.
Active means operations are running.
Partially Committed means operations done but not saved.
Committed means changes saved permanently.
Failed and Aborted mean rollback due to error.
Transaction ends after commit or abort.
Full Transcript
A transaction in a database management system goes through several states. It starts with the 'Start' state when the transaction begins. Then it moves to 'Active' while operations are performed. After operations, if the transaction is successful, it moves to 'Partially Committed' where all operations are done but changes are not yet permanent. Then it moves to 'Committed' where changes are saved permanently. Finally, the transaction ends successfully. If an error occurs during 'Active', the transaction moves to 'Failed' and then 'Aborted', rolling back changes and ending the transaction without saving. This flow ensures data integrity and consistency.

Practice

(1/5)
1. Which of the following is NOT a valid state of a database transaction?
easy
A. Running
B. Waiting
C. Committed
D. Failed

Solution

  1. Step 1: List common transaction states

    Common transaction states include Running (active), Waiting (blocked), Committed (successfully completed), and Aborted (rolled back).
  2. Step 2: Identify invalid state

    "Failed" is not a standard transaction state; instead, "Aborted" or "Rolled back" is used for unsuccessful transactions.
  3. Final Answer:

    Failed -> Option D
  4. Quick Check:

    Standard states exclude "Failed" [OK]
Hint: Remember standard states: Running, Waiting, Committed, Aborted [OK]
Common Mistakes:
  • Confusing 'Failed' with 'Aborted'
  • Thinking 'Waiting' is not a state
  • Assuming 'Failed' is official terminology
2. Which SQL command is used to move a transaction from the 'Running' state to the 'Committed' state?
easy
A. ROLLBACK
B. COMMIT
C. SAVEPOINT
D. BEGIN

Solution

  1. Step 1: Understand transaction commands

    ROLLBACK undoes changes, SAVEPOINT sets a restore point, BEGIN starts a transaction, and COMMIT finalizes changes.
  2. Step 2: Identify command to commit

    COMMIT is the command that moves a transaction from Running (active) to Committed (completed) state.
  3. Final Answer:

    COMMIT -> Option B
  4. Quick Check:

    COMMIT finalizes transaction [OK]
Hint: COMMIT saves changes permanently, ROLLBACK cancels [OK]
Common Mistakes:
  • Confusing ROLLBACK with COMMIT
  • Using SAVEPOINT to commit
  • Thinking BEGIN commits
3. Consider the following sequence of SQL commands in a transaction:
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

What is the final state of this transaction after execution?
medium
A. Committed
B. Aborted
C. Running
D. Waiting

Solution

  1. Step 1: Analyze the transaction commands

    The transaction starts with BEGIN, performs two updates, then ends with COMMIT.
  2. Step 2: Determine transaction state after COMMIT

    COMMIT finalizes the transaction successfully, so the state becomes Committed.
  3. Final Answer:

    Committed -> Option A
  4. Quick Check:

    COMMIT means transaction is Committed [OK]
Hint: COMMIT means transaction completed successfully [OK]
Common Mistakes:
  • Thinking transaction remains Running after COMMIT
  • Confusing Aborted with Committed
  • Assuming Waiting state after COMMIT
4. Identify the error in this transaction sequence:
BEGIN;
UPDATE inventory SET quantity = quantity - 5 WHERE product_id = 10;
ROLLBACK;
COMMIT;
medium
A. COMMIT after ROLLBACK is invalid
B. ROLLBACK should come after COMMIT
C. BEGIN is missing
D. No error, sequence is correct

Solution

  1. Step 1: Understand ROLLBACK and COMMIT order

    ROLLBACK cancels the transaction, so no changes remain to commit afterwards.
  2. Step 2: Identify invalid command sequence

    After ROLLBACK, issuing COMMIT is invalid because the transaction is already aborted.
  3. Final Answer:

    COMMIT after ROLLBACK is invalid -> Option A
  4. Quick Check:

    Cannot COMMIT after ROLLBACK [OK]
Hint: ROLLBACK cancels; no COMMIT allowed after rollback [OK]
Common Mistakes:
  • Thinking COMMIT can follow ROLLBACK
  • Assuming ROLLBACK should come after COMMIT
  • Missing BEGIN statement
5. A transaction is in the 'Waiting' state because it is blocked by another transaction holding a lock. Which of the following actions will NOT help the waiting transaction to proceed?
hard
A. The blocking transaction commits
B. The blocking transaction rolls back
C. The waiting transaction issues a COMMIT
D. The blocking transaction releases the lock

Solution

  1. Step 1: Understand 'Waiting' state cause

    Waiting occurs when a transaction is blocked due to locks held by another transaction.
  2. Step 2: Analyze actions that unblock waiting

    If the blocking transaction commits, rolls back, or releases the lock, the waiting transaction can proceed.
  3. Step 3: Identify action that does NOT help

    The waiting transaction issuing COMMIT while blocked cannot proceed because it must first acquire the lock.
  4. Final Answer:

    The waiting transaction issues a COMMIT -> Option C
  5. Quick Check:

    Waiting means blocked; only blocking transaction actions help [OK]
Hint: Only blocking transaction actions unblock waiting transaction [OK]
Common Mistakes:
  • Thinking waiting transaction can commit while blocked
  • Assuming waiting state ends without lock release
  • Confusing roles of blocking and waiting transactions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard