0
0
SQLquery~20 mins

Auto-commit behavior in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Auto-commit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Effect of Auto-commit ON after INSERT

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?

SQL
INSERT INTO employees (id, name) VALUES (101, 'Alice');
SELECT COUNT(*) FROM employees;
AThe count will be zero because auto-commit rolls back changes automatically.
BThe count does not include the new row until a COMMIT is issued.
CThe SELECT query will cause an error because the transaction is not committed.
DThe count includes the new row inserted (count increased by 1).
Attempts:
2 left
💡 Hint

Think about what auto-commit means for each statement.

query_result
intermediate
2:00remaining
Effect of Auto-commit OFF on UPDATE visibility

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?

SQL
UPDATE products SET price = price * 1.1 WHERE category = 'Books';
SELECT COUNT(*) FROM products WHERE price > 100;
AThe SELECT reflects the updated prices because the UPDATE is visible in the session.
BThe SELECT does not see the updated prices until COMMIT is issued.
CThe SELECT query will fail due to uncommitted changes.
DThe SELECT returns zero because updates are rolled back automatically.
Attempts:
2 left
💡 Hint

Consider transaction isolation and visibility within the same session.

📝 Syntax
advanced
2:00remaining
Disabling Auto-commit in SQL Session

Which of the following SQL commands correctly disables auto-commit mode in a session for a standard SQL database?

ASET AUTOCOMMIT = OFF;
BBEGIN TRANSACTION;
CCOMMIT AUTOCOMMIT OFF;
DDISABLE AUTOCOMMIT;
Attempts:
2 left
💡 Hint

Think about the standard command to toggle auto-commit mode.

🧠 Conceptual
advanced
2:00remaining
Impact of Auto-commit on Transaction Rollback

In a database session with auto-commit enabled, what happens if you execute an UPDATE statement and then issue a ROLLBACK command?

AThe ROLLBACK causes an error because no transaction is active.
BThe ROLLBACK undoes the UPDATE because it is part of the current transaction.
CThe ROLLBACK has no effect because the UPDATE was already committed automatically.
DThe ROLLBACK commits the UPDATE instead of undoing it.
Attempts:
2 left
💡 Hint

Consider when auto-commit commits changes relative to ROLLBACK.

🔧 Debug
expert
3:00remaining
Diagnosing Unexpected Data Visibility with Auto-commit OFF

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?

ABecause auto-commit is disabled, changes are immediately visible to all sessions.
BBecause uncommitted changes in Session 1 are not visible to other sessions.
CBecause Session 2 is running in autocommit mode and ignores uncommitted changes.
DBecause the UPDATE statement failed silently in Session 1.
Attempts:
2 left
💡 Hint

Think about transaction isolation and visibility across sessions.