Consider a database session where auto-commit is enabled by default. You run the following SQL commands:
INSERT INTO employees (id, name) VALUES (101, 'Alice'); SELECT COUNT(*) FROM employees;
What will the SELECT query return immediately after the INSERT?
INSERT INTO employees (id, name) VALUES (101, 'Alice'); SELECT COUNT(*) FROM employees;
Think about what auto-commit means for each statement.
With auto-commit ON, each statement is committed immediately after execution. So the INSERT is committed before the SELECT runs, making the new row visible.
In a session where auto-commit is disabled, you execute:
UPDATE products SET price = price * 1.1 WHERE category = 'Books'; SELECT COUNT(*) FROM products WHERE price > 100;
Assuming no COMMIT or ROLLBACK has been issued yet, what will the SELECT query return?
UPDATE products SET price = price * 1.1 WHERE category = 'Books'; SELECT COUNT(*) FROM products WHERE price > 100;
Consider transaction isolation and visibility within the same session.
Even with auto-commit OFF, uncommitted changes are visible within the same session. So the SELECT sees the updated prices.
Which of the following SQL commands correctly disables auto-commit mode in a session for a standard SQL database?
Think about the standard command to toggle auto-commit mode.
Setting AUTOCOMMIT = OFF disables auto-commit mode in many SQL databases. Other options are either invalid or start a transaction but do not disable auto-commit globally.
In a database session with auto-commit enabled, what happens if you execute an UPDATE statement and then issue a ROLLBACK command?
Consider when auto-commit commits changes relative to ROLLBACK.
With auto-commit ON, each statement is committed immediately. So ROLLBACK cannot undo changes already committed.
You have auto-commit disabled and run these commands in two separate sessions:
-- Session 1: UPDATE accounts SET balance = balance - 100 WHERE id = 1; -- no COMMIT yet -- Session 2: SELECT balance FROM accounts WHERE id = 1;
Session 2 still shows the old balance. Why?
Think about transaction isolation and visibility across sessions.
Uncommitted changes are only visible within the same session. Other sessions see the old data until a COMMIT is issued.