TOPIC 24/2815 MINNOT STARTED

Stored procedures and triggers: logic inside the database

Some rules run inside the database as stored procedures and triggers. Learn how to test code you cannot see on the screen.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a machine behind a wall. A machine sorts mail whenever a letter drops in. People see the letter go in and a sorted pile come out. They do not see the machine.

To test it, you check what goes in and what comes out.

Daily List is a to-do list app. Some of its rules run inside the database. Tom, the tester, tests those rules by the rows they change.

What it is: A is named (Structured Query Language) kept in the database. You call it by name. It can change rows. A database trigger is code that runs by itself when a row changes. Both are hidden logic when the only place you look is the screen. A table is a grid, a row is one item, and a column is one fact about that item. A trigger is easy to mix up with a procedure. You call a procedure. A trigger calls itself.

Why it matters: A screen can mark a task done and never show the log line the trigger wrote. A procedure can move rows into an archive the screen does not list. Tom checks those tables, or he will miss the bug.

(SYNTHETIC / TRAINING ONLY: Daily List and every person named in this lesson are invented.)

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Testing a machine behind a wall by what goes in and what comes out.

  1. In
  2. Out
  3. Compare
Machine behind a wall

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The machineA procedure or trigger
The letter going inInputs or a row change
The sorted pileData after
The wallHidden from the screen

WHERE THIS PICTURE STOPS

  • A machine is seen if you open the wall, but code needs to be read.
  • A machine runs when fed, but a trigger runs by itself.
  • A machine has one job, but a trigger may cause others.

HOOK

In, out, compare.

TELL A FRIEND

A machine behind a wall: check in and out.

OFTEN MIXED UP WITH Database transactions, ACID and isolation: testing for half-saved data. That topic covers half-finished changes. This one covers logic that runs inside the database.

PRACTISE AND KEEP

Sources for this topic — 5 sources
  1. Market practice

    SQL Server stored procedures vs functions vs views ↗ — SQLServerCentral · SQLServerCentral article: a view takes no parameters, a function returns a value and a procedure can change data (search excerpt, page not opened)

    View takes no parameters; function returns a value; procedure can change data. · Checked 2026-10-19

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    How to write unit tests for MySQL stored procedures (OneUptime) ↗ — OneUptime · OneUptime article: wrap tests of a procedure that changes data in a transaction and roll back (search excerpt, page not opened)

    Wrap data-changing procedure tests in a transaction and roll back. · Checked 2026-10-19

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Market practice

    How to Test Triggers? (forum thread) ↗ — SQLServerCentral · SQLServerCentral thread: ways to confirm that a trigger fired and what it changed (search excerpt, page not opened)

    Ways to confirm that a trigger fired and what it changed. · Checked 2026-10-19

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Implementation-specific

    PostgreSQL documentation ↗ — The PostgreSQL Global Development Group · PostgreSQL 18 official manual, opened 2026-11-06: xproc §36.4 and SQLite CREATE TRIGGER. Supports only PostgreSQL behavior; earlier execution evidence remains separately versioned.

    A free, precise, section-numbered description of the SQL a payments practitioner actually writes. Join types and what happens to unmatched rows, GROUP BY and HAVING against WHERE, window functions and the de-duplication and running-total idioms built on them. Transaction isolation levels and the anomalies each permits, index use, and null three-valued logic.

    Used here for the data-and-SQL questions a Payment Operations Analyst, a Production Support Analyst and a Sanctions Screening Analyst are asked. · Checked 2026-08-18

    An implementation, not the standard — which is the point. ISO/IEC 9075-2 is paywalled, and this documents the same constructs in text anybody can open. Its isolation-level chapter attributes to the standard explicitly, so it can carry a standard-level claim as long as the citation says which document it is quoting.

    Cited as market practice rather than an official standard by kind: an engine's manual is authoritative about that engine and is not the obligation. Where a question turns on behaviour PostgreSQL chose rather than behaviour SQL requires, the answer has to say so.

    One correction carried here because it circulates widely: the sentence "The fundamental difference between WHERE and HAVING…", quoted all over the internet as PostgreSQL documentation, is not in the current documentation. It was searched for in the source tree and is not there.

    Read through a mirror, because the publisher's own domain could not be fetched (a reachability gap, not a statement about the publisher). A 403 there is a policy refusal and says nothing about whether the document exists or is reachable elsewhere.

    Anyone on an unrestricted network should open the canonical URL above and confirm the section and page numbers cited against it. Every claim drawn from this entry is written so that it can be checked against a numbered page.

    Read from the postgres/postgres documentation source tree (doc/src/sgml), which the project itself maintains and which carries the section ids the published URLs are derived from — so a cited section id can be checked against the rendered page.

  5. Implementation-specific

    SQLite official documentation — constraints, types and transactions ↗ — SQLite · SQLite rolling official documentation, opened 2026-11-06: foreignkeys.html, datatype3.html, lang_createtable.html, lang_transaction.html, isolation.html, cli.html, series.html and lang_createtrigger.html as relevant. Historical SQLite 3.40.1 results remain distinct from in-memory audit witnesses on 3.53.1.

    Implementation-specific SQLite documentation, not a universal SQL standard. Includes foreign-key enforcement, type affinity, CREATE TABLE/TRIGGER, explicit/implicit transaction behavior, isolation, CLI and series extension references. · Checked 2026-11-06

    Relevant primary pages opened 6 November2026; rolling documentation and CLI examples (3.54.0) are distinct from historical lesson runs3.40.1 and audit witnesses3.53.1. No file/connected database audit execution.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.