{"canonical_url":"https://engineer.company/glossary/normalization/","content_markdown":"# Database normalization\n\n## What it is\n\nDatabase normalization is the practice of laying out a relational database so\nthat each fact is stored once, in the table it describes, and everything else\nrefers to it by its key. In British spelling it is database normalisation. A\ncustomer's address sits in one row of a customers table; an order carries only\nthe customer's key, and a join brings the two together when a query needs both.\n\nThe idea and the word both come from Edgar F. Codd, who proposed the relational\nmodel in Communications of the ACM in June 1970. In that paper normalization\nmeant one particular step: getting rid of relations that hold other relations\ninside them, such as an employee record that carries its own list of past jobs\nand its own list of children. Codd's procedure copies the parent's primary key\ninto each nested group and lifts the group out into a relation of its own, keyed\nby the parent's key plus whatever identifies a row within the group. What is\nleft is in normal form, now known as first normal form: every value in every\ncolumn is a single, simple value.\n\nCodd went on to define stricter normal forms, among them the one that Ronald\nFagin's 1977 paper calls Codd's improved third normal form, also known as\nBoyce–Codd normal form. Fagin's paper adds a fourth. It rests on a new kind of\ndependency between columns, the multivalued dependency, which includes the\nfamiliar functional dependency as a special case, and Fagin showed the fourth\nform to be strictly stronger than Boyce–Codd normal form.\n\nThe stricter forms are reached by splitting. A table is replaced by two or more\nof its projections, tables made of some of its columns, chosen so that joining\nthem gives back exactly the original. Fagin's paper shows that guarantee holds\nfor its own form: any table can be split into tables in fourth normal form\nwithout losing information, because joining them recovers the original.\nDenormalization is the reverse: keeping a copy of a fact in a second place on\npurpose, usually to save a join.\n\n## Why it matters\n\nA table that stores the same fact many times invites three kinds of trouble.\nPicture one row per employee and project, with the employee's office repeated on\nevery row. When someone changes office, several rows need the new value, and\nmissing one leaves the database contradicting itself. When an employee's last\nproject ends and its row is deleted, the record of where they sit goes with it.\nAnd a new hire who is not on any project has nowhere to record an office. These\nare the update, deletion and insertion anomalies, and splitting the table into\nemployee–project and employee–office removes all three.\n\nIn a team's daily work these anomalies arrive as bugs. An invoice shows the old\naddress because one copy was missed. A report counts a customer twice because\nthe name was typed two ways. A normalized schema makes such bugs hard to write\nin the first place, and with primary keys, foreign keys and check constraints\ndeclared, the database refuses bad data itself instead of trusting every piece\nof application code to remember the rules.\n\nChange gets cheaper too. A schema whose tables each describe one thing tends to\nabsorb new kinds of data with less restructuring: adding a column to the one\ntable that owns a fact is a smaller migration than finding every table that\ncopied it.\n\nThe price is joins. A normalized database answers most questions by joining\ntables back together, and each join is work for the server. With indexes on the\njoined columns that work is usually small, which is why a measured slow query,\nand not a hunch, should decide when a fact gets copied back in.\n\n## What it looks like in practice\n\nA small shop starts with one flat table, loaded from a spreadsheet export:\n\n```sql\nCREATE TABLE order_flat (\n    order_no       integer,\n    ordered_on     date,\n    customer_email text,\n    customer_name  text,\n    customer_city  text,\n    sku            text,\n    product_name   text,\n    unit_price     numeric,\n    quantity       integer,\n    status         text\n);\n```\n\nEach row is one line of one order, so a customer's name and city repeat on every\nline of every order, and a product's name repeats on every line that sells it. A\ncustomer who moves has dozens of rows to update. Deleting the last line that\nsold a product forgets that the product exists. The status is free text, so\n`shipped`, `Shipped` and `shipd` can all turn up.\n\nNormalized, each fact gets one home:\n\n```sql\nCREATE TABLE customers (\n    customer_id integer PRIMARY KEY,\n    email       text NOT NULL UNIQUE,\n    name        text NOT NULL,\n    city        text NOT NULL\n);\n\nCREATE TABLE products (\n    sku        text PRIMARY KEY,\n    name       text NOT NULL,\n    list_price numeric NOT NULL CHECK (list_price \u003e= 0)\n);\n\nCREATE TABLE order_status (\n    status_id smallint PRIMARY KEY,\n    label     text NOT NULL UNIQUE\n);\n\nCREATE TABLE orders (\n    order_id    integer PRIMARY KEY,\n    customer_id integer NOT NULL REFERENCES customers ON DELETE RESTRICT,\n    status_id   smallint NOT NULL REFERENCES order_status,\n    ordered_on  date NOT NULL\n);\n\nCREATE TABLE order_lines (\n    order_id   integer REFERENCES orders ON DELETE CASCADE,\n    sku        text NOT NULL REFERENCES products,\n    quantity   integer NOT NULL CHECK (quantity \u003e 0),\n    unit_price numeric NOT NULL CHECK (unit_price \u003e= 0),\n    PRIMARY KEY (order_id, sku)\n);\n```\n\nA customer's city is now stored once, and a move is a one-row update. The status\nlabels sit in a small lookup table keyed by a `smallint`, so each order carries\na short number instead of a repeated string, and a misspelt status cannot get\nin: the foreign key refuses any `status_id` that `order_status` does not hold.\n\n`unit_price` stays on `order_lines`, although `products` already has a price.\nThat is no lapse. The price a customer paid is a fact about the sale, not about\nthe product, and it must not change when the catalogue does. Normalization asks\nwhere each fact belongs, and this one belongs to the line.\n\nThe two `ON DELETE` clauses say what a deletion means. Deleting an order takes\nits lines with it, since a line means nothing without its order. Deleting a\ncustomer who has orders fails, because those orders are records the shop has to\nkeep. PostgreSQL's default, `NO ACTION`, refuses that deletion too; `RESTRICT`\nstates the intent, and unlike `NO ACTION` it cannot be deferred to the end of\nthe transaction.\n\nPostgreSQL builds an index for every primary key, but not for the referencing\nside of a foreign key. Its documentation suggests adding one, because deleting\nor updating a referenced row has to find every row that points at it:\n\n```sql\nCREATE INDEX ON orders (customer_id);\nCREATE INDEX ON order_lines (sku);\n```\n\n`order_lines.order_id` needs nothing extra: it is the leading column of that\ntable's primary key.\n\nFinally, a view puts the flat shape back for whoever wants it:\n\n```sql\nCREATE VIEW order_report AS\nSELECT o.order_id, o.ordered_on, c.email, c.name AS customer_name, c.city,\n       l.sku, p.name AS product_name, l.unit_price, l.quantity, s.label\nFROM   orders o\nJOIN   customers c    USING (customer_id)\nJOIN   order_status s USING (status_id)\nJOIN   order_lines l  USING (order_id)\nJOIN   products p     USING (sku);\n```\n\nReports can read `order_report` much as they read the old table, while every\nfact behind it is stored once. The PostgreSQL tutorial makes the same case for\nviews in general: a view gives a query a name that can be used like a table, and\nlets the tables underneath change behind an interface that stays put.\n\nThe same rules hold at a far larger scale. In the founder's work under\nNextMariner, the\n[maritime data model](/portfolio/modeled-348-tables-across-34-postgres-schemas/)\nwas laid out as normalized PostgreSQL schemas organised by domain, which its\npage put at 348 tables across 34 schemas in October 2026. Small, stable sets\nsuch as statuses, types and categories became `SMALLINT` lookup tables, which\nkeeps rows compact and joins cheap, and real foreign keys and constraints hold\nthe relationships together, so that integrity is the database's job rather than\nsomething the application has to remember.\n\n## Where it goes wrong\n\n**Lists packed into one column.** A `tags` column holding `red,large,sale`, or a\nphone column holding two numbers, breaks first normal form. The database cannot\ncheck the separate values, point a foreign key at them or join on them, and\nevery query has to split the string first. Give the list a table of its own, one\nrow per value, keyed by the parent's key plus the value: Codd's procedure from\n1970.\n\n**Normalizing away history.** The price on an order line, or the delivery\naddress on an order, looks like a duplicate of what the products and customers\ntables hold. It is not one: it records what was true when the order was placed.\nSwap it for a key into the current catalogue, and every old invoice changes the\nnext time a price does. Keep facts about an event on the event.\n\n**Foreign keys without indexes.** The referenced side of a foreign key is always\nindexed, since it has to be a primary key or a unique constraint or index. The\nreferencing side is not, so deleting a customer, or changing a product's SKU,\nmeans scanning the whole referencing table for rows that point at it. Index the\nreferencing columns, as above. PostgreSQL leaves that to you because it is not\nalways needed.\n\n**Cascades that delete records.** `ON DELETE CASCADE` from customers to invoices\nmeans one careless delete of a customer quietly removes records the business\nneeds to keep. Cascade only to rows that mean nothing without their parent, such\nas order lines, and use `RESTRICT`, or the default, everywhere else.\n\n**A normalized design that nothing enforces.** Tables created by hand or loaded\nfrom spreadsheets often arrive with no primary key and no foreign keys, so\nnothing stops a duplicate row or an order for a customer who does not exist.\nPostgreSQL does not insist on a primary key, though its documentation notes that\nrelational theory requires one in every table. Declare the keys, and the\ndatabase rejects the bad row with an error that names the constraint.\n\n**Cached totals that drift.** An `order_total` column on `orders`, kept beside\nthe lines it sums, is a denormalization, and every code path that changes a line\nhas to update it as well. One that forgets leaves the total wrong without\nraising any error. Compute the total in a query or a view. If that proves too\nslow, keep the copy, but maintain it in one place, inside the same transaction\nthat changes the lines.\n\n**Denormalizing before measuring.** Joins on indexed keys are cheap, and copying\ncolumns to avoid them trades a small, known cost for the anomalies described\nabove. Read the query plan first. When reads really are too slow, a materialized\nview or a separate reporting database can hold the flattened shape while the\nsource tables keep a single copy of each fact. Reporting is where\ndenormalization is at home on purpose, as in the star schema of a data\nwarehouse.\n\n**Splitting too far.** Normalization asks for one home per fact, not for as many\ntables as possible. Splitting a table whose columns already depend on its key\nand on nothing else only adds joins, and table names for everyone to learn. A\nschema that needs a dozen joins to show one order is no easier to work with than\na flat one. Stop once each fact has a single home.\n\n## Further reading\n\n- [A Relational Model of Data for Large Shared Data Banks](https://doi.org/10.1145/362384.362685)\n  — Codd's 1970 paper in Communications of the ACM, which introduced the\n  relational model, normal form and normalization.\n- [Multivalued Dependencies and a New Normal Form](https://doi.org/10.1145/320557.320571)\n  — Fagin's 1977 paper defining the multivalued dependency and fourth normal\n  form, and showing that any table can be split into fourth normal form without\n  losing information.\n- [Constraints](https://www.postgresql.org/docs/current/ddl-constraints.html) —\n  PostgreSQL on primary keys, foreign keys, check constraints and the\n  `ON DELETE` actions, and why referencing columns are worth indexing.\n- [Views](https://www.postgresql.org/docs/current/tutorial-views.html) — the\n  PostgreSQL tutorial's case for views as a stable interface over tables whose\n  structure changes.\n\n\u003chttps://engineer.company/glossary/normalization/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"What database normalization is, from Codd's normal forms to foreign keys in PostgreSQL, the anomalies it removes and the mistakes made in its name.","formats":{"gemtext":"https://engineer.company/glossary/normalization/index.gmi","gopher":"https://engineer.company/glossary/normalization/gophermap","html":"https://engineer.company/glossary/normalization/","json":"https://engineer.company/glossary/normalization/index.json","markdown":"https://engineer.company/glossary/normalization/index.md","pdf":"https://engineer.company/glossary/normalization/index.pdf"},"kind":"page","language":"en","title":"What is database normalization?","url":"https://engineer.company/glossary/normalization/","version":1}