CodeBlanks Logo Icon CodeBlanks

SAVEPOINT

Do a partial rollback.

SAVEPOINT

A SAVEPOINT marks a point inside a transaction. It allows partial rollback.

BEGIN;
INSERT INTO orders VALUES (1, 50);
SAVEPOINT sp1;
INSERT INTO orders VALUES (2, 100);
ROLLBACK TO sp1;
COMMIT;

The second INSERT is undone, the first stays.

SAVEPOINT — details

With SAVEPOINT you can undo part of a transaction. Without breaking the whole transaction.

For example, after SAVEPOINT s1; you can undo a faulty step with ROLLBACK TO s1 and continue while keeping the earlier changes.

Practice SAVEPOINT

Set a SAVEPOINT sp1 and roll back to it with ROLLBACK TO sp1.

Starter code

query.sql
-- savepoint
SAVEPOINT

Sample solution

query.sql
BEGIN;
INSERT INTO orders VALUES (1, 50);
SAVEPOINT sp1;
INSERT INTO orders VALUES (2, 100);
ROLLBACK TO sp1;
COMMIT;

Expected output

Savepoint oluşturuldu

Questions and answers

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

1 What does SAVEPOINT provide?

  • A full rollback
  • A partial rollback Correct answer
  • Automatic saving
  • A speed boost

Explanation: SAVEPOINT provides partial rollback.

2 Add SAVEPOINT

Question
____ sp1;
Answer
SAVEPOINT sp1;

Explanation: SAVEPOINT is the right answer.

3 SAVEPOINT: match the terms

Term Meaning
SAVEPOINT mark
ROLLBACK TO partial undo
COMMIT commit
partial half

All lessons in Intermediate