Database Transaction

Context: FIT2094_MOC ยท groups DML into one logical unit ยท the frame for ACID, locking and recovery

Quick Revision

  • ๐ŸŽฏ Objective: bundle several DML statements into one all-or-nothing unit โž” COMMIT saves all, ROLLBACK undoes all.
  • โšก Key Constraint: a mid-transaction state is inconsistent; a failure between steps must ROLLBACK the earlier ones โ€” partial commit is never allowed.

๐Ÿ“ Core

  • Definition โž” a group of SQL operations executed completely or not at all.
  • COMMIT โž” save all changes permanently; ROLLBACK โž” undo all changes since the last commit.
  • Scope โž” transaction control applies to INSERT/UPDATE/DELETE only (DDL auto-commits, see SQL Sublanguages (DDL, DML, DCL)).
  • Worked case (drone return) โž” (1) UPDATE rental return date/condition/emp_no_in, (2) UPDATE drone add flight time, (3) COMMIT โ€” all three are one logical operation.

โš ๏ธ Common Mistakes

  • ๐Ÿ’ก No COMMIT/ROLLBACK for DDL โž” they apply only to DML; a CREATE/ALTER is already permanent.
  • ๐Ÿ’ก Partial success = corruption โž” if step 2 fails after step 1 commits data, the drone shows returned with no flight time logged; ROLLBACK the whole unit instead.

๐Ÿง  Active Recall