The Lawfare Academy

Lawfare Group → Knowledge Institute → Lawfare Academy

← Data Management and SQL for Business

Unit 1

Data models and business meaning

Learning objectives

  • Explain data models and business meaning in your own words.
  • Apply the principle to the worked business case.
  • Evaluate the answer and identify an assumption that could change it.

Data models and business meaning

A data model represents entities, attributes, and relationships. Define what each row means before writing queries. Distinguish a customer, a job, an invoice, and a payment so one event is not mistaken for another.

Worked example

One job can have several invoices and each invoice several payments. A flat list can duplicate job revenue.

Current on-site learning

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.

Work through the reasoning

Define the business workflow, data, users, system boundary, and failure consequences. For this unit, connect the explanation of data models and business meaning to the worked example before answering the practice question.

Check the limits

Test a representative case and identify controls, exceptions, recovery, and the accountable human owner. If the source model and the practical example use different assumptions, state the difference rather than applying the formula or rule mechanically.

Apply it independently

What should be defined first? Write an answer before opening the model response. Show the calculation or explain the causal or logical steps. Change one material assumption and say whether your conclusion changes. This practice is optional; you can read every part of the course without submitting work.

Original Academy expansion: make the business meaning explicit

A database is a set of claims about a business, expressed in a structure that determines which questions can be answered reliably. Start with the grain: what does one row represent? A customer row might represent a billing account, a person, or a household. A job row might represent an appointment, a work order, or an entire contract. Those are different entities. A query cannot repair an ambiguous definition after the fact. Write a short data dictionary stating each table's grain, identifier, important attributes, and time interpretation.

For the fictional Cedar Service laboratory, customers represent billing accounts, jobs represent work orders, job_lines represent separately priced lines on a work order, and payments represent payment events allocated to one work order. One customer can have several jobs. One job can have several lines and several payments. This structure deliberately separates two one-to-many relationships that later create a common double-counting error. Every amount in the laboratory is an integer number of cents. The examples omit tax, refunds, credit notes, and multi-invoice allocations so the accounting assumptions remain explicit.

An entity has identity even when its descriptive fields change. A customer changing a telephone number should not become a new customer merely because the phone number was used as a key. A natural key comes from the business domain, such as an externally guaranteed account code. A surrogate key is introduced as an identifier, such as customer_id. A surrogate key does not remove the need to enforce real business uniqueness where required. If two accounts must not share the same external code, that rule requires its own constraint.

Separate current state from historical events. A customer's current address cannot reconstruct the address used for an invoice two years ago unless the relevant history was retained. A job's current status cannot reveal every prior status transition unless transitions were recorded. Sometimes a document should preserve a snapshot even when a customer master record changes. Other questions need a valid-from/valid-to history. Decide what historical question must be supported before overwriting a field.

Normalization is a method of reducing harmful dependencies, not a command to maximize the number of tables. If every job repeats the customer's current contact address, changing that address may require many updates and leave inconsistent copies. Move attributes dependent on the customer to the customer table, while retaining genuinely document-specific facts on the document. A fact such as the agreed price on a historical job line should usually remain on that line; changing today's price list should not rewrite what the customer agreed to pay earlier.

Worked investigation: a deceptively convenient spreadsheet

Imagine one sheet with customer_name, customer_phone, job_id, job_status, line_description, line_price, payment_date, and payment_amount. Job 101 has two price lines and two payments. Representing all combinations can require four rows. The same line price and payment can appear repeatedly. Summing either column now risks inflating totals. Keeping one row per job instead forces lists of lines or payments into cells, making individual constraints and queries difficult. The issue is a mismatch between several grains, not simply an untidy spreadsheet.

Use four tables instead. customers stores account identity, jobs stores the work-order relationship and status, job_lines stores each priced line, and payments stores each receipt. Foreign keys express the allowed relationships. Queries can then aggregate each grain before combining results. If one payment can cover several jobs, add a payment header and allocation table rather than pretending the one-job payment model still applies. Schema design must change when the business relationship changes.

NULL represents missing or inapplicable information under a chosen convention. It is not automatically zero or an empty string. A NULL completion date might mean unfinished, unknown, or not applicable; using one value for three meanings may need an accompanying status or reason field. In SQL, comparisons involving NULL generally yield UNKNOWN rather than TRUE or FALSE. The WHERE clause retains TRUE rows. Therefore completion_date = NULL is not the test for missing dates; use IS NULL. Business semantics come first, followed by correct SQL mechanics.

Progressive practice

  1. Foundation: state the grain and primary key for customers, jobs, job_lines, and payments.
  2. Application: explain where the agreed historical line price belongs when the current price list changes.
  3. Transfer: one receipt pays two jobs. Describe the additional relationship needed without duplicating the receipt.
  4. Critique: a report labels every NULL completion date as a late job. Identify at least two alternative meanings that must be checked.

Worked reasoning for the practice

The grains are one billing account, one work order, one priced work-order line, and one payment event allocated to a work order. Their identifiers are customer_id, job_id, line_id, and payment_id. Historical agreed price belongs with the historical line, while current list price is a different fact. For shared receipts, retain a single payment event and introduce allocations with their own allocation amounts and job references. A missing completion date could identify unfinished work, an unrecorded date, or a canceled job. A late-work query needs a due date, an as-of date, and status rules in addition to missingness.

Reading alignment for this expansion

The earlier introductory links remain background reading. Use the complete current on-site studios; publisher links are optional provenance. The original Academy worked records above are not quotations from those sources.

Open the runnable laboratory

Extended text lesson

Continue with Normalize the facts while preserving their meaning for the full worked case, source readings and optional progressive practice.

Complete current conceptual preparation

Manage a business fact from collection to a defensible decision

Data are observations; information requires a question

An amount of 50000 is not yet a usable sales fact. State its currency and scale, whether it is a quote, issued invoice or settled receipt, its identifier, time basis, source and correction status. In integer cents it may mean $500; in whole dollars it means $50,000. A database preserves representations of claims, not automatic truth. Information emerges when a defined transformation answers a defined question. A management recommendation adds further assumptions about costs, behavior and uncertainty. Keep those layers separate so that a convenient field name cannot substitute for evidence.

The existing Cedar model already distinguishes billing accounts, work orders, priced lines and payment events. Preserve those grains. This studio adds a lifecycle and system contract around them. A collection form should identify the originator and validation rule; storage should preserve identity and access authority; cleaning should retain the raw input and reason for a change; transformation should be versioned; a report should name its population and cutoff; later correction should remain traceable. Choosing a modern database cannot repair a missing business definition.

A conceptual model is a set of relationship claims

Before choosing SQL types, draw or describe the permitted entities and cardinalities. One billing account may have zero or many work orders; each accepted order must belong to one account in this stipulated process. Each order can contain multiple priced lines, identified by order and line number. A payment event and its allocations may be separate entities when one receipt can pay multiple orders. Optionality matters: allowing a draft order without an account is a policy different from requiring a known account before any order is saved. State which lifecycle states allow the exception and which transition must resolve it.

A conceptual entity model describes the domain. A logical relational model maps entities and relationships into tables, keys and constraints. A physical design selects engine-specific types, indexes, storage and access paths. An index may accelerate a lookup without changing the logical meaning of an order; splitting one payment into duplicate rows changes that meaning even if the report is faster. Evaluate correctness at the logical grain before optimizing the physical implementation. A many-to-many relationship generally needs an associative relation, such as payment_allocations(payment_id,order_id,allocated_cents), whose rows represent allocations rather than new receipts.

The catalog describes the schema: table and column names, types and declared constraints. A business dictionary must add meaning that the engine cannot infer, such as whether paid means authorized, captured or settled; whether a timestamp is local time or UTC; whether canceled orders remain in a denominator; and who owns a definition. A column can be technically non-null yet contain a plausible but wrong customer identifier. Catalog checks and stewardship complement each other rather than replace one another.

DBMS responsibilities and application responsibilities

A DBMS stores and retrieves data under its declared transaction, constraint and access behavior. It parses a query, selects an execution strategy and obtains the relevant records. SQLite is an embedded engine; its library compiles SQL into a program that is executed by a virtual machine. Its planner and storage layers implement mechanisms, not the business policy that a report should include only settled receipts. A server database adds a different connection and deployment architecture; its role features and concurrency rules must be checked for that engine rather than assumed from SQLite.

A spreadsheet or flat file can be appropriate for a bounded single-user dataset. A DBMS can centralize constraints, concurrent access and reproducible querying, but introduces administration, recovery, schema evolution and security responsibilities. Copying a shared spreadsheet into SQL without reconciling duplicate identities merely relocates the defect. Conversely, an isolated synthetic teaching file does not need a production cluster to demonstrate a three-row join. Select a system based on workload, integrity, recovery and authority requirements, not just row count or a product label.

Operational processing records individual events reliably. Analytical reporting combines selected events at a declared grain and cutoff. A reporting store may intentionally retain a historical snapshot or a denormalized representation for a defined purpose. It must explain refresh timing and reconciliation to sources; a daily extract is not a real-time balance simply because its chart updates in a browser. Preserve the original normalized transaction-price case: current catalog changes must not rewrite issued order-line prices.

Worked investigation: a small data-quality ledger

Use an independent synthetic raw receipt import with four rows. R 1 is 12500 cents for account A, R 2 is 7500 cents for account B, a second identical R 2 row repeats the same event, and R 3 is 4000 cents with account unresolved. The raw row sum is 31500 cents. A validated unique-event ledger retains R 1,R 2,R 3 once each, totaling 24000 cents. Known-account assigned receipts total 20000 cents; unresolved receipts total 4000 cents. These are three different measures: raw rows, unique events and resolved assignments.

Deduplicating R 2 is justified only because the external event identifier and payload establish the same receipt under a declared replay policy. Two genuine equal-value payments are not duplicates merely because they share amount and date. R 3's unknown account is not automatically zero revenue, a fictitious account 0 or a receipt to discard. If the intended measure is all unique settled receipts, include 24000 cents and disclose the unresolved allocation. If it is receipts allocated to known accounts, report 20000 and the separate 4000 suspense balance. A manager asking which account paid most needs the second population and its limitation.

Completeness, uniqueness, consistency, accuracy and timeliness answer different questions. Three of three unique receipts have amounts, so amount-field completeness is 100%. Only two of three have resolved accounts, so account-resolution completeness is 2/3. An event identifier uniquely represented once does not establish that its amount matches the bank. A raw duplicate rate of one extra row among four is 25%, whereas the fraction of distinct event identities affected by duplication is 1/3. Label the denominator. If a later authorized correction allocates R 3 to B, B becomes 11500 cents, A remains 12500 and unique total stays 24000. Preserve the original unresolved state and the correction evidence rather than rewriting the historical import as though it arrived complete.

Governance and roles that make the contract actionable

A business data owner approves meaning and permitted uses. A steward maintains definitions, quality exceptions and reconciliation. A database administrator manages engine configuration, recovery and access mechanisms. A data engineer builds ingestion and transformations; an analyst interprets the resulting measures. Small organizations may combine roles, but should still separate a proposed correction from authority to approve it. A successful query does not authorize access to private records. Use synthetic fixtures for practice and grant production access only through the actual organization's policy.

Quality controls should record the rule, detection time, affected identifiers, disposition, approving authority and reprocessing consequence. Avoid retaining unnecessary sensitive fields simply because storage is cheap. Access, retention, deletion and recovery have legal and operational dimensions requiring the applicable policy; this unit makes no specific retention-period claim. Florida is the contemporary state-law default when legal examples are later supplied, with federal obligations and explicit comparisons identified separately.

Optional practice and complete changed-fact models

Guided model: three receipt totals

Raw sum 12500+7500+7500+4000=31500 cents. Unique-event sum 12500+7500+4000=24000. Known-account sum 12500+7500=20000, with 4000 unresolved. Changed fact: the second 7500 row has distinct verified event IDR 4. It is a separate payment, so the unique total becomes 31500 rather than 24000. Equality of values alone does not authorize deduplication.

Independent model: a denominator and a correction

Amount completeness is 3/3 for unique events, account resolution 2/3. One extra raw duplicate among four rows is 25%; one affected event among three is 1/3. Changed fact: R 3 is validly assigned to B. B becomes 11500 cents and assignment completeness 3/3, while total receipts stay 24000. Retain the correction ledger and distinguish current resolved reporting from the original as-received snapshot.

Transfer model: a fast report with the wrong grain

A dashboard sums a receipt once per allocation and calls it total collections. An event allocated to two orders is counted twice. Aggregate allocated amounts at allocation grain or receipts at event grain according to the measure, and reconcile the two only under a valid full-allocation contract. Changed fact: one receipt is partially unallocated. The sum of allocations can legitimately be below total receipts; report the suspense difference instead of fabricating an allocation to force equality.

Unit rubric: 20 points

Award four points each for event/entity/relationship and time definitions; logical-versus-physical/system responsibilities; reproducible unique-event and assignment calculations; quality/governance/provenance controls; and changed-fact reasoning with a valid report population. Complete model keeps receipts distinct from allocations, produces 31500/24000/20000 and 4000 suspense under the original import, reports 2/3 resolution and preserves authorized corrections. A database constraint is necessary for some invariants but cannot prove every real-world fact.

Optional source summaries: OpenStax data-management focus was read for metadata, quality, governance and the relationship between managing data and analytical decisions. This studio supplies its own teaching and receipt ledger; no external chapter is required. SQLite architecture was read to confirm the distinction between SQL compilation, execution, planning and storage mechanisms. Those engine mechanisms do not supply business definitions or access authority. The examples above are original and use no real account or learner data.

Apply the idea

One job can have several invoices and each invoice several payments. A flat list can duplicate job revenue.

What should be defined first? Explain your reasoning, then identify one changed fact that could alter the conclusion.

Expanded transfer investigation: A customer changes address. Which statement is correct for historical invoicing?

Show the calculation or argument, identify the information available at the decision time, and state which assumption supports your conclusion. The four progressive tasks in the Learn stage provide additional practice.

Read the worked reasoning

The meaning and key of each record. Reliable analysis starts with the grain of the data. In an independent response, state the given facts, identify the governing relationship, work through the calculation or comparison, and distinguish the conclusion from assumptions that still need evidence.

Expanded transfer reasoning: A snapshot or suitable history supports the required historical question.

Progressive practice reasoning: The grains are one billing account, one work order, one priced work-order line, and one payment event allocated to a work order. Their identifiers are customer_id, job_id, line_id, and payment_id. Historical agreed price belongs with the historical line, while current list price is a different fact. For shared receipts, retain a single payment event and introduce allocations with their own allocation amounts and job references. A missing completion date could identify unfinished work, an unrecorded date, or a canceled job. A late-work query needs a due date, an as-of date, and status rules in addition to missingness.

Check understanding

One job has multiple priced lines and multiple payment events. What is a defensible starting schema?

  1. Separate job, line, and payment grains with explicit relationships
    Feedback

    Correct. Separate event grains allow integrity constraints and controlled aggregation.

  2. Store every line-payment combination and sum all amount columns
    Feedback

    Incorrect. Combinations repeat both measures and create fanout.

  3. Put all payment amounts in one comma-separated job field
    Feedback

    Incorrect. A list in one field obscures individual events and their constraints.

Further reading

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.

My learning →