AvailableIncluded in beta access

Micro-course · Beginner / intermediate

Keep data reliable with constraints

Stop invalid data in the right place with types, keys and constraints.

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

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

The business problem

Negative prices, duplicate emails and orphaned orders make reports unreliable.

What you will be able to do

Choose and write the right constraint for a simple business rule.

  • Use NOT NULL, UNIQUE and CHECK
  • Connect two tables with a foreign key
  • Choose a constraint instead of a trigger

Scope of this micro-course

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

Prerequisites

  • Tables, columns and primary keys

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

    Validation only in the interface can be bypassed by an import, an API or another process. The base must protect invariants which remain true whatever the writing path.

    Open lesson
  2. 02
    Build a controllable method

    Use the simplest constraint that expresses the rule: type for technical domain, NOT NULL for obligation, UNIQUE for uniqueness, CHECK for a local condition, and FOREIGN KEY for a relationship.

    Open lesson
  3. 03
    Check before interpreting

    Test a valid insert and then each violation separately. Give meaningful names to important constraints so that the error is exploitable.

    Open lesson
  4. 04
    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
  5. 05
    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
  6. 06
    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

Practical exercises

  1. 01
    Guarantee integrity with real constraints

    Create and test PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, NOT NULL and DEFAULT.

    Do exercise
  2. 02
    Create a controlled table for invoicing 2 training scenario

    Create a structure that rejects duplicate IDs and negative values. 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
    Create a controlled table for logistics 3 training scenario

    Create a structure that rejects duplicate IDs and negative values. 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
    Create a controlled table for rh 4 · training scenario

    Create a structure that rejects duplicate IDs and negative values. 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
    Create a controlled table for audit 5 · training scenario

    Create a structure that rejects duplicate IDs and negative values. 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
    Detect duplicate emails

    Transform a uniqueness constraint into measurable control.

    Do exercise
  7. 07
    Reconcile orders and payments

    Compare two independent totals in a single control line.

    Do exercise
  8. 08
    Measure phone completeness

    Produce a quality rate from explicit volumes.

    Do exercise

Back to the full catalogue