ACID & Basic Transactions — Series 2

Preview — 3 of 10 questions

After this block runs, what is accounts.balance for id = 1?

javascript
-- accounts.balance for id = 1 starts at 500
BEGIN;
UPDATE accounts SET balance = 100 WHERE id = 1;
ROLLBACK;
A500
B100
CNULL
DAn error — you cannot ROLLBACK after an UPDATE has already run

Session A runs BEGIN; UPDATE accounts SET balance = 100 WHERE id = 1; (no COMMIT yet). At that exact moment, Session B (a separate connection) runs SELECT balance FROM accounts WHERE id = 1;. What does Session B see?

javascript
-- Session A:
BEGIN;
UPDATE accounts SET balance = 100 WHERE id = 1;
-- (not yet committed)

-- Session B (concurrently):
SELECT balance FROM accounts WHERE id = 1;
-- sees the OLD value, e.g. 500  Session A's change is invisible until COMMIT
A100 — Session B immediately sees Session A's uncommitted change
BThe original (pre-update) balance — Session A's change is not visible to any other session until Session A commits
CAn error — Session B's query is blocked and fails until Session A finishes
DNULL, because the row is temporarily locked

Which statement correctly describes PostgreSQL's syntax for starting a transaction?

javascript
BEGIN;
BEGIN WORK;
BEGIN TRANSACTION;
START TRANSACTION;   -- the SQL-standard spelling
AOnly BEGIN (with no suffix) is valid — BEGIN WORK and BEGIN TRANSACTION are syntax errors
BSTART TRANSACTION only works for SERIALIZABLE transactions
CBEGIN WORK, BEGIN TRANSACTION, and START TRANSACTION are all equivalent ways to start a transaction
DBEGIN WORK starts a read-only transaction, while BEGIN alone starts a read-write one

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.