Transaction behavior: when AUTOCOMMIT is ON, are changes committed automatically at the end of each SQL statement?

Difficulty: Easy

Correct Answer: Correct

Explanation:


Introduction / Context:
AUTOCOMMIT controls how your session ends transactions. Understanding this setting prevents surprises such as unintended commits or uncommitted work. The question asks whether, with AUTOCOMMIT enabled, each statement is committed automatically when it finishes.



Given Data / Assumptions:

  • A data modification statement (INSERT, UPDATE, DELETE, certain DDL) changes data or schema.
  • A transaction commits when changes are made durable and visible to other sessions.
  • AUTOCOMMIT setting is per-session behavior in many tools and drivers.


Concept / Approach:
With AUTOCOMMIT ON, each successful statement is its own transaction: the platform issues an implicit COMMIT after that statement completes successfully. If the statement fails, changes are implicitly rolled back. With AUTOCOMMIT OFF, multiple statements can be grouped into a single transaction until an explicit COMMIT or ROLLBACK is issued.



Step-by-Step Solution:

Check AUTOCOMMIT state: ON means commit-per-statement.Run a DML statement; upon success, the system auto-commits.Run another statement; it executes in a new transaction and auto-commits again.Conclude that AUTOCOMMIT ON commits after each statement completes successfully.


Verification / Alternative check:
Open two sessions: in one, with AUTOCOMMIT ON, perform an UPDATE; in the second session, immediately SELECT the affected rows—changes are visible without an explicit COMMIT in the first session.



Why Other Options Are Wrong:

  • Incorrect: Misunderstands AUTOCOMMIT semantics.
  • Only for SELECT: SELECT does not modify data; AUTOCOMMIT concerns transactions around DML/DDL.
  • Only after SAVEPOINT / session end: These refer to manual control or session lifecycle, not AUTOCOMMIT behavior.


Common Pitfalls:
Forgetting AUTOCOMMIT is ON and making irreversible changes; assuming a tool’s UI default equals the server’s default.



Final Answer:
Correct

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion