Lawfare Group → Knowledge Institute → Lawfare Academy

← Course syllabus · Related lesson

Normalize the facts while preserving their meaning

Current complete on-site edition 6

Required teaching and complete optional models are supplied on LawfareGroup.com. Publisher and primary links are optional provenance or further reading. Florida is the contemporary state-law default; federal rules and explicitly comparative accounting frameworks are distinguished. Independent subject review and observed human learner testing remain pending.

Cumulative data-system dossier, transfer models and 30-point rubric

Preserved original teaching integrated with complete current on-site preparation. Independent human subject review and observed learner testing remain pending.

Learning objectives

Write down what one row claims

An export repeats customer names, order dates and product information on every order line. Its rows are (O1,line1,C1,North,2026-01-05,P1,2,10), (O1,line2,C1,North,2026-01-05,P2,1,30), and (O2,line1,C1,North,2026-01-06,P1,3,10). The final two values are quantity and the transaction’s unit price. The intended grain is one order line, identified by the pair (order_id,line_no). Repeated product P1 is not a duplicate line: it occurs on two different orders.

For this model, an order_id determines customer_id and order_date; customer_id determines the current customer name; and (order_id,line_no) determines product_id, quantity and transaction unit price. A functional dependency is a rule about all valid states in the intended domain, not merely an accidental pattern in these three rows. The fact that all observed orders belong to C1 does not mean that customer_id determines order_id. Use business semantics and identifiers to distinguish a rule from a coincidence.

Likewise, product_id does not necessarily determine transaction unit price. The same product can be sold at different dates, discounts or contract prices. Moving the observed line price into a single current product record would silently change the represented fact. Good normalization starts by identifying the meaning and time basis of the attributes, rather than by removing every repeated-looking value.

Explain the anomaly and the decomposition

If the customer’s current name changes, the export requires changing three copies. Updating only two creates inconsistent current names. Storing a customer before it has an order may be impossible in a table whose required key is an order line. Deleting its final line may accidentally delete the only recorded current name. These are update, insertion and deletion anomalies arising from storing facts of different grains in one relation.

Decompose into customers(customer_id PRIMARY KEY,name), orders(order_id PRIMARY KEY,customer_id REFERENCES customers,order_date), and lines(order_id REFERENCES orders,line_no,product_id,quantity,unit_price,PRIMARY KEY(order_id,line_no)). In this fixture, keep the transaction price on lines. Appropriate NOT NULL and domain checks make required attributes explicit. A product table may hold product descriptions and current catalog prices, but it does not replace the historical price agreed for an order line.

The reconstruction joins each line to exactly one order and each order to exactly one customer. Parent-key uniqueness prevents multiplication, and valid non-NULL references prevent dropped child facts for this inner-join reconstruction. Check those conditions rather than assuming a join is lossless because it executes. A name table that contains two rows for C1 can double every line; a missing order parent can remove a line. Constraints and exact-pair comparisons make the intended decomposition auditable.

Validate facts at the original grain

O1 totals 2×10+1×30=50, and O2 totals 3×10=30. The grand total is 80. A successful reconstruction must preserve not only that total but every keyed line, its customer, date, quantity and unit price. Two offsetting price changes can retain 80 while corrupting individual transactions. Compare both directions of an exact set difference, and separately check multiplicity when the original representation permits duplicates. An EXCEPT comparison uses set semantics and cannot by itself prove duplicate counts are preserved.

In the runnable fixture, both the original export and the reconstructed table have a unique composite line key, so equality of keyed rows establishes the relevant row-level preservation. In a less constrained staging table, first inspect duplicate key counts and conflicting attributes. Do not use DISTINCT to make inconsistent source rows disappear without a reconciliation policy. Correctness is a statement about the intended facts, not just the number of rows a query happens to return.

Current names and invoice-time names can legitimately differ. If issued documents must retain the name used at issuance, model an immutable document snapshot or a versioned relationship in addition to the current customer master. Updating a current master then changes current-name reports while leaving the issuance snapshot intact. This is a choice of facts and history, not a defect that can be solved by insisting on either universal duplication or universal removal of duplication.

Normalization also does not prove that an identifier was assigned correctly, an amount was measured accurately, or an application has appropriate permissions. Preserve source provenance, units, date conventions and update authority. Test schema constraints with invalid records in a disposable fixture, then assess any operational migration separately. The in-memory demonstration is an explanation of a small model; it is not evidence that a production conversion, concurrent import or retention policy has been validated.

Worked example: The exact reconstruction ledger

The original and normalized reconstructions contain the same three keyed lines. O1=50, O2=30 and total=80. Inserting another line with the existing key (O1,1) must fail. A duplicate product code on a different valid line is allowed. These tests distinguish the identity rule from an overly broad uniqueness rule on product_id.

Worked example: A price change that must not rewrite the past

Suppose P1 now has a catalog price of 12. Retaining transaction prices of 10 keeps O1=50 and O2=30. Recomputing historical lines with the new catalog price would produce O1=54 and O2=36, total=90. Both queries can be fast and syntactically valid; only the first preserves the stipulated transaction-price fact.

Progressive optional practice

Attempt each problem before opening its model. Then revise the reasoning under the changed conditions.

Guided

State the row key and three functional dependencies for the export.

Compare the model reasoning

The key is (order_id,line_no). Order_id determines customer_id and date; customer_id determines the modeled current name; the composite line key determines product, quantity and transaction price.

Changed conditions

The same customer has many orders.

Compare the revised analysis

That is consistent with these dependencies and disproves the mistaken reverse dependency customer_id→order_id.

Independent

Design checks proving the normalization preserved the three lines and their amounts.

Compare the model reasoning

Enforce key uniqueness, validate references, compare all keyed attributes in both directions and reconcile O1=50, O2=30, total=80. Explain why totals alone are insufficient.

Changed conditions

The staging export contains duplicate copies of one line.

Compare the revised analysis

Set difference alone can conceal multiplicity. Investigate duplicate keys and provenance before selecting or rejecting rows; do not silently deduplicate conflicting facts.

Transfer

Should an invoice-time customer name always come from the current customer table?

Compare the model reasoning

No. Specify whether the report needs the current name or the name at issuance. Preserve historical snapshots or versions when required by the document model; do not overwrite history to satisfy a current-master dependency.

Changed conditions

A catalog price changes to 12.

Compare the revised analysis

Keep agreed transaction prices on historical lines. Using the new catalog price changes the totals to 54 and 36 in the fixture and no longer answers the historical question.

Source readings and scope

Database Design, 2nd edition: normalization — Original-author textbook reading on dependencies and anomalies. Order model, reconstruction and historical-price analysis are original Academy material.

SQLite: CREATE TABLE — Reference for primary keys and constraints.

SQLite: foreign key support — Reference for enforcing the reconstruction relationships.

Reproduce the worked examples in Python 3. Standard library only; synthetic data; no production records or network access.