{
    "slug": "db_normalisation_forms",
    "term": "Database Normalisation",
    "category": "database",
    "difficulty": "intermediate",
    "short": "The process of structuring a relational database to reduce redundancy and improve integrity, defined through progressive normal forms (1NF through BCNF).",
    "long": "Normalisation eliminates update anomalies caused by duplicated data. First Normal Form (1NF): atomic values, no repeating groups. Second Normal Form (2NF): no partial dependencies on composite keys. Third Normal Form (3NF): no transitive dependencies. Boyce-Codd Normal Form (BCNF): every determinant is a candidate key. In practice, 3NF satisfies most applications. Denormalisation — intentional violation for read performance — is acceptable when backed by measured need.",
    "aliases": [
        "1NF",
        "2NF",
        "3NF",
        "BCNF",
        "normal forms"
    ],
    "tags": [
        "database",
        "sql",
        "design",
        "fundamentals"
    ],
    "misconception": "Higher normal forms are always better — denormalisation is often the right call for read-heavy reporting tables where join overhead outweighs storage savings.",
    "why_it_matters": "Unnormalised tables cause update anomalies — change a customer's address in one order row and it silently differs from other rows, producing inconsistent data with no error.",
    "common_mistakes": [
        "Storing comma-separated values in a single column — violates 1NF and makes querying impossible without string parsing.",
        "Repeating customer name and address in every order row instead of a foreign key to a customers table.",
        "Normalising reporting/analytics tables that need fast aggregations — calculated columns or materialised views are better there.",
        "Conflating normalisation with performance — always normalise first, then denormalise specific tables with measurement."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "db_foreign_keys",
        "db_schema_design",
        "data_normalisation",
        "db_views"
    ],
    "prerequisites": [
        "database_indexing",
        "db_schema_design",
        "data_integrity"
    ],
    "refs": [
        "https://en.wikipedia.org/wiki/Database_normalization"
    ],
    "bad_code": "-- Unnormalised: customer data repeated in every order row\nCREATE TABLE orders (\n    id INT PRIMARY KEY,\n    customer_name VARCHAR(100),  -- Repeated for every order\n    customer_email VARCHAR(100), -- Update in one row, others stale\n    customer_address TEXT,\n    product VARCHAR(100),\n    quantity INT\n);",
    "good_code": "-- 3NF: customer data stored once, referenced by FK\nCREATE TABLE customers (\n    id INT PRIMARY KEY,\n    name VARCHAR(100),\n    email VARCHAR(100) UNIQUE,\n    address TEXT\n);\nCREATE TABLE orders (\n    id INT PRIMARY KEY,\n    customer_id INT REFERENCES customers(id),\n    product_id INT REFERENCES products(id),\n    quantity INT\n);",
    "quick_fix": "Aim for 3NF in OLTP databases: eliminate repeating groups (1NF), remove partial dependencies on composite keys (2NF), and remove transitive dependencies (3NF) — denormalise only when query performance requires it",
    "severity": "medium",
    "effort": "high",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/db_normalisation_forms",
        "html_url": "https://codeclaritylab.com/glossary/db_normalisation_forms",
        "json_url": "https://codeclaritylab.com/glossary/db_normalisation_forms.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Database Normalisation](https://codeclaritylab.com/glossary/db_normalisation_forms) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/db_normalisation_forms"
            }
        }
    }
}