CodeBlanks Logo Icon CodeBlanks

Summary - Transaction

Write a money transfer with BEGIN, COMMIT and ROLLBACK.

Summary - Transaction

A transaction starts with BEGIN, commits with COMMIT or rolls back with ROLLBACK. It provides ACID properties.

BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

Summary transfer.

Practice Summary - Transaction

Summary: write a money transfer transaction (BEGIN, two UPDATEs, COMMIT).

Starter code

query.sql
-- write summary

Sample solution

query.sql
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

Expected output

Transaction tamamlandı

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What do you do on error?

  • SAVEPOINT
  • COMMIT
  • BEGIN
  • ROLLBACK Correct answer

Explanation: On error you ROLLBACK.

2 Summary - Transaction: match the terms

Term Meaning
BEGIN start
COMMIT commit
ROLLBACK undo
ACID reliable

All lessons in Intermediate