TOPIC 18/2816 MINNOT STARTED

CREATE, ALTER and DROP: how tables are made, changed and removed

Learn what the three table statements do, what to test when a table is changed, and why a drop needs a backup and a check of what depends on it.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a classroom cupboard. The teacher builds a cupboard with labelled shelves. Later she adds a shelf. At the end of term she takes the whole cupboard away, with everything in it. Building is routine. Taking it away is final.

Daily List is a to-do list app. A release adds a reminders table, then a column for the channel, and someone may later drop the table. Tom plans a different test for each of those three. (SYNTHETIC / TRAINING ONLY: Daily List and the people here are invented.).

What it is: CREATE TABLE makes a table. ALTER TABLE changes one that exists. DROP TABLE removes it. (Structured Query Language) is the language of those three statements. A table is a grid. A row is one record, such as one reminder. A column is one fact, such as when to remind Lily. The neighbour of DROP TABLE is DELETE. DELETE removes rows and leaves the table. DROP removes the table itself. TRUNCATE is a third neighbour in PostgreSQL and MySQL. It empties a table quickly. PostgreSQL can roll that empty back. MySQL cannot, because TRUNCATE there commits at once. SQLite has no TRUNCATE statement. A DELETE with no WHERE is how you empty a table there.

Why it matters: The can refuse a good row. A can break an old screen because a new column is null. A table removal can break a view that a report still uses. Tom checks dependencies before anyone drops a table on a shared test database.

PLAIN WORDS · 2 in this section
empties
becomes empty, or drains into somewhere else
sqlite
a small free database tool

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 A classroom cupboard with labelled shelves.

  1. Build
  2. Change
  3. Remove
Cupboard

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
Building the cupboardCREATE TABLE
Adding a shelfALTER TABLE add COLUMN
Taking the cupboard awayDROP TABLE
A shelf labelA column type

WHERE THIS PICTURE STOPS

  • A cupboard is built by hand, but a table is built by a statement.
  • Removal is slow in a room, but a drop is instant.
  • Shelves hold objects, but columns hold typed values.

HOOK

Take it away, lose the contents.

TELL A FRIEND

A cupboard: building is routine, removal is final.

OFTEN MIXED UP WITH SQL (Structured Query Language) CRUD (create, read, update, delete) for testers: INSERT, SELECT, UPDATE and DELETE. That topic covers working with rows. This one covers making, changing and removing the table itself.

PRACTISE AND KEEP

Sources for this topic — 4 sources
  1. Market practice

    Altering tables (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL guide: a table can be changed after it is made, to add a column, remove a column, rename it or change its type (search excerpt, page not opened)

    §5.7 altering columns and constraints. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: §5.7 altering columns and constraints. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  2. Market practice

    DROP TABLE (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL reference: drop table removes the table and its data, and refuses by default if other objects depend on it unless cascade is given (search excerpt, page not opened)

    DROP TABLE dependency RESTRICT/CASCADE scope. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: DROP TABLE dependency RESTRICT/CASCADE scope. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  3. Implementation-specific

    PostgreSQL documentation ↗ — The PostgreSQL Global Development Group · PostgreSQL 18 official manual, opened 2026-11-06: ddl-alter §5.7, sql-droptable and tutorial-transactions. 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.

  4. 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.