0
0
SQLquery~20 mins

BEGIN TRANSACTION syntax in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Transaction Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output after running this transaction block?
Consider the following SQL commands executed in order:

BEGIN TRANSACTION;
INSERT INTO accounts (id, balance) VALUES (1, 100);
UPDATE accounts SET balance = balance + 50 WHERE id = 1;
ROLLBACK;

What is the balance of the account with id = 1 after these commands?
SQL
BEGIN TRANSACTION;
INSERT INTO accounts (id, balance) VALUES (1, 100);
UPDATE accounts SET balance = balance + 50 WHERE id = 1;
ROLLBACK;
ANo row with id = 1 exists
BBalance is 150
CBalance is 100
DBalance is 50
Attempts:
2 left
💡 Hint
ROLLBACK undoes all changes made in the transaction.
📝 Syntax
intermediate
1:30remaining
Which option correctly starts a transaction in standard SQL?
Choose the correct syntax to begin a transaction in standard SQL.
ASTART TRANSACTION;
BOPEN TRANSACTION;
CBEGIN;
DBEGIN TRANSACTION;
Attempts:
2 left
💡 Hint
Standard SQL uses a specific phrase to start transactions.
🧠 Conceptual
advanced
2:00remaining
What happens if you execute multiple BEGIN TRANSACTION statements without COMMIT or ROLLBACK?
In a database session, what is the effect of running multiple BEGIN TRANSACTION commands consecutively without committing or rolling back the previous transaction?
AThe second BEGIN TRANSACTION is ignored until commit or rollback
BEach BEGIN TRANSACTION starts a new nested transaction
CThe previous transaction is automatically committed before starting a new one
DThe second BEGIN TRANSACTION causes an error
Attempts:
2 left
💡 Hint
Most databases do not support nested transactions by default.
optimization
advanced
2:00remaining
How to optimize transaction usage for multiple related updates?
You need to update multiple related tables in a database. Which approach optimizes performance and data integrity?
ARun each update in its own transaction
BRun updates without any transaction
CRun all updates inside a single transaction
DRun updates with autocommit enabled
Attempts:
2 left
💡 Hint
Grouping related changes in one transaction helps consistency.
🔧 Debug
expert
2:30remaining
Why does this transaction block cause an error?
Examine the following SQL code:

BEGIN TRANSACTION;
INSERT INTO orders (id, amount) VALUES (1, 100);
BEGIN TRANSACTION;
UPDATE orders SET amount = 150 WHERE id = 1;
COMMIT;

Why does this code cause an error?
SQL
BEGIN TRANSACTION;
INSERT INTO orders (id, amount) VALUES (1, 100);
BEGIN TRANSACTION;
UPDATE orders SET amount = 150 WHERE id = 1;
COMMIT;
ACOMMIT is missing after the first BEGIN TRANSACTION
BNested BEGIN TRANSACTION is not allowed without commit or rollback
CINSERT statement syntax is incorrect
DUPDATE statement causes a type error
Attempts:
2 left
💡 Hint
Check if nested transactions are supported.