2. Which SQL statement correctly starts a transaction in MySQL?
easy
A. BEGIN TRANSACTION;
B. START TRANSACTION;
C. OPEN TRANSACTION;
D. INIT TRANSACTION;
Solution
Step 1: Recall MySQL transaction syntax
MySQL uses START TRANSACTION; to begin a transaction.
Step 2: Check other options
Options A, B, and D are not valid MySQL commands for starting transactions.
Final Answer:
START TRANSACTION; -> Option B
Quick Check:
MySQL uses START TRANSACTION [OK]
Hint: Use START TRANSACTION to begin in MySQL [OK]
Common Mistakes:
Using BEGIN TRANSACTION which is not valid in MySQL
Confusing with other SQL dialects
Typing incorrect keywords like OPEN or INIT
3. Consider this sequence in MySQL:
START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
What ACID property does this sequence mainly demonstrate?
medium
A. Consistency - data types are checked
B. Isolation - changes are visible immediately
C. Durability - changes are temporary
D. Atomicity - all changes happen or none
Solution
Step 1: Understand the transaction sequence
The two updates are grouped inside a transaction with COMMIT at the end.
Step 2: Identify the ACID property
Atomicity ensures either both updates happen or none do, preventing partial changes.
Final Answer:
Atomicity - all changes happen or none -> Option D
Quick Check:
Transaction groups changes atomically [OK]
Hint: Atomicity means all or nothing in transactions [OK]
Common Mistakes:
Confusing Isolation with Atomicity
Thinking Durability means temporary changes
Assuming Consistency only checks data types
4. You wrote this MySQL transaction:
START TRANSACTION;
UPDATE inventory SET quantity = quantity - 5 WHERE product_id = 10;
COMMIT;
But sometimes the quantity becomes negative. What ACID property is likely violated?
medium
A. Consistency
B. Isolation
C. Durability
D. Atomicity
Solution
Step 1: Analyze the problem
Quantity becoming negative means data rules are broken.
Step 2: Identify violated ACID property
Consistency ensures data stays valid and follows rules; here it is violated.
Final Answer:
Consistency -> Option A
Quick Check:
Consistency keeps data valid [OK]
Hint: Consistency means data must follow rules always [OK]
Common Mistakes:
Thinking Atomicity prevents negative values
Confusing Isolation with data validity
Assuming Durability fixes data rules
5. In a multi-user MySQL environment, two transactions run:
Transaction 1:
START TRANSACTION;
UPDATE accounts SET balance = balance - 50 WHERE id = 1;
-- waits before COMMIT
Transaction 2:
START TRANSACTION;
SELECT balance FROM accounts WHERE id = 1;
COMMIT;
Which ACID property ensures Transaction 2 does not see the uncommitted balance change from Transaction 1?
hard
A. Atomicity
B. Durability
C. Isolation
D. Consistency
Solution
Step 1: Understand concurrent transactions
Transaction 1 updates but delays commit; Transaction 2 reads the same data.