AvailableIncluded in beta access

Micro-course · Intermediate

Secure an operation with transactions

Make several related changes succeed or fail together.

60 to 75 minCommon SQL · PostgreSQL6 lessons · 8 activities available
Start the course

Free 30-day beta access · no payment · progress saved

The business problem

An order is recorded but its payment fails, leaving an incomplete state.

What you will be able to do

Use COMMIT, ROLLBACK and SAVEPOINT while understanding errors and concurrency.

  • Define a transaction boundary
  • Undo an operation
  • Use a savepoint
  • Understand isolation

Scope of this micro-course

This micro-course targets one focused skill. It does not replace a complete path or server administration training.

Prerequisites

  • INSERT, UPDATE and DELETE

Project and practice

8 verified exercises are available. Validation is based on the programme exercises.

Focused path

Your programme, in order.

Content remains centralised: completing an activity here also updates the path that contains it.

Micro-lessons

  1. 01
    The problem to solve before syntax

    A UPDATE without WHERE can modify an entire table. A restarted import can also create duplicates if the uniqueness and conflict behavior are not defined.

    Open lesson
  2. 02
    Build a controllable method

    First write the SELECT that identifies the lines, run the change in a transaction, use RETURNING to observe the effects, and explicitly choose the conflict key of the UPSERT.

    Open lesson
  3. 03
    Check before interpreting

    Check the number of records returned before and after, check the returned values and test resuming the import. A safe operation is repeatable or explicitly non-repeatable.

    Open lesson
  4. 04
    The problem to solve before syntax

    Debiting inventory and then failing before creating the order leaves an inconsistent state. Two transactions can also read the same stock and sell the last unit simultaneously.

    Open lesson
  5. 05
    Build a controllable method

    Group the writes that form one decision in BEGIN/COMMIT. A transaction does not guarantee that an UPDATE matches a row. Here the order is inserted only from rows reserved by UPDATE…RETURNING: no stock means no order. Use ROLLBACK to undo the operation and SAVEPOINT to recover a substep.

    Open lesson
  6. 06
    Check before interpreting

    Try zero stock, a missing product, then a stock of two: expect zero, zero and one order respectively. Introduce an error between two writes and roll back. This embedded lab supports atomicity tests; conflicts between two sessions need PostgreSQL server, not this single-user instance.

    Open lesson

Practical exercises

  1. 01
    Secure an operation with transactions

    Check the status before and after validation, cancellation and partial return.

    Do exercise
  2. 02
    Protect a billing change 2 training scenario

    Commit a correct change and undo only the incorrect step. You must produce the result, check it on the source data and explain what it allows you to decide in this billing system.

    Do exercise
  3. 03
    Protect a logistics change 3 training scenario

    Commit a correct change and undo only the incorrect step. You must produce the result, check it on the source data and explain what it allows you to decide in this national expeditions.

    Do exercise
  4. 04
    Protect an HR change 4 · training scenario

    Commit a correct change and undo only the incorrect step. You must produce the result, control it on the source data and explain what it allows you to decide in this human resources management.

    Do exercise
  5. 05
    Protect an audit change 5 training scenario

    Commit a correct change and undo only the incorrect step. You must produce the result, check it on the source data and explain what it allows you to decide in this audit log.

    Do exercise
  6. 06
    Edit data without losing control

    Practice writes, their edge cases and an idempotent operation.

    Do exercise
  7. 07
    Insert then update billing data 2 · training scenario

    Make two controlled changes and check the final state. You must produce the result, check it on the source data and explain what it allows you to decide in this billing system.

    Do exercise
  8. 08
    Insert then update logistics data 3 · training scenario

    Make two controlled changes and check the final state. You must produce the result, check it on the source data and explain what it allows you to decide in this national expeditions.

    Do exercise

Back to the full catalogue