ACCT 320 · Accounting Information Systems
Designing Data Models
A data model plans which things a business tracks and how they link, using entity diagrams and normalization to avoid repeated facts.
Key takeaways
- A data model lists the entities (things the business tracks), their attributes (facts about each) and the relationships between them.
- An entity-relationship diagram (ERD) draws the model, with a line for each relationship and a mark showing one or many on each end.
- Cardinality says how many rows on one side can match the other: one or many, required or optional.
- Normalization removes repeated and tangled facts in steps called normal forms; most business databases aim for third normal form.
- The REA model, which tracks resources, events and agents, is an accounting-friendly way to start a model.
Rosa has decided to move Spoke & Mirror off the big spreadsheet. A friend offers to build her a database over a weekend. "Just tell me what columns you need," he says. Rosa lists everything she can think of and hands over a page of 30 column names. By Monday the friend is stuck: Is "supplier phone" a fact about the supplier or about each order? Where do bike sizes go? What happens when one order has five items?
Nobody should build the tables first. First comes a data model: a plan that says what things the business keeps track of, what facts belong to each, and how they connect. Think of it as the blueprint before the house. This lesson shows how accountants and designers draw that blueprint, and how to fix a bad one.
Three words to start with
An entity is a kind of thing the business keeps facts about: Customer, Product, Sale, Employee. It becomes a table. An attribute is one fact about an entity: a customer's name or a product's price. It becomes a column. A relationship is a link between two entities: a customer places sales.
If you can say it as a plain sentence, it is probably a relationship. "A customer places many sales." "A sale contains many products." "An employee works many shifts." Writing the sentences first is a good habit, because each one becomes a line in the diagram.
The entity-relationship diagram
An entity-relationship diagram, or ERD, draws entities as boxes with their attributes listed inside, and relationships as lines between boxes. The ends of each line show cardinality with a simple code: a single bar for "one" and a three-pronged fork (called crow's foot) for "many."
For Spoke & Mirror, a first sketch has four entities.
- Customer: CustomerID, Name, Phone
- Sale: SaleID, Date, CustomerID
- Product: ProductID, Name, Price, Cost
- SaleLine: SaleID, ProductID, Quantity
The sentences behind it: one Customer places many Sales. One Sale has many SaleLines. One Product appears in many SaleLines. SaleLine is the junction table, which you met in relational databases for accountants, and its primary key is the pair SaleID plus ProductID.
Cardinality: counting both ends
Cardinality states how many of one entity can link to the other, read in both directions. Ask two questions for every line.
- Can one customer have more than one sale? Yes, many. Can a sale have more than one customer? In this shop, no, one.
- Must a sale have a customer? If walk-ins pay cash and give no name, then no, it is optional. Rosa must decide whether to invent a "Walk-in customer" row or allow a blank. Either way, write the rule down.
Getting these answers wrong creates real accounting trouble. If the model says a sale can never exist without a customer, the register will refuse cash sales to strangers. Worse, staff may type fake names to get past the block, which spoils the data.
The REA model
Accountants have their own starting point called the REA model, which stands for Resources, Events and Agents.
- Resources are things of value the business controls: cash, inventory, equipment.
- Events are business activities that change resources: a sale, a purchase, a cash receipt.
- Agents are the people and organizations who take part: customers, suppliers, employees.
Spoke & Mirror's sale event gives up the resource inventory, gains the resource cash, involves the agent Customer and the agent Salesperson. The beauty of REA is that it models what actually happens, in plain business terms, and the debits and credits can be produced from events later. It also forces you to ask "who was involved?" for each event, which is exactly what auditors ask.
Normalization: tidying the tables
Even a well-drawn ERD can lead to messy tables. Normalization is a step-by-step cleanup that removes repeated and tangled facts. Each step is called a normal form. For business databases, three steps usually do the job.
First normal form (1NF). Every cell holds a single value, and there are no repeating groups. A cell reading "Tube, Pump, Lock" in one column breaks this rule. Fix it by giving each item its own row.
Second normal form (2NF). Already 1NF, and every non-key column depends on the whole primary key, not just part of it. This matters when the key has two parts. In SaleLine, Quantity depends on both SaleID and ProductID: it is the quantity of that product on that sale. But a ProductName column would depend only on ProductID, so it belongs in Product. Move it out.
Third normal form (3NF). Already 2NF, and no non-key column depends on another non-key column. Suppose Customer holds Name, ZIP code and City. City follows from ZIP, not from the customer. Move ZIP and City to their own table, or drop one.
A handy memory line: every non-key column should depend on "the key, the whole key, and nothing but the key."
A worked example: normalizing one messy table
Here is Rosa's friend's first attempt, a single table called Orders, with one row per product on a sale.
| SaleID | Date | CustomerName | CustomerPhone | ProductName | Price | Qty |
|---|---|---|---|---|---|---|
| 5001 | Mar 3 | Nina Park | 555-0142 | City bike | 400 | 1 |
| 5003 | Mar 9 | Nina Park | 555-0142 | Tire tube | 5 | 3 |
| 5004 | Mar 9 | Omar Reyes | 555-0177 | Tire tube | 5 | 2 |
Count the repeats. Nina's name and phone appear twice. The tire tube's name and price appear twice. If the tube price rises to 6, we must change two rows now and many more later.
Step 1: split by kind of thing. Customer facts go to a Customer table with a CustomerID. Product facts go to a Product table with a ProductID. Sale facts, the date and who bought, go to a Sale table. The product-on-sale quantities go to SaleLine.
Step 2: replace the repeated text with keys. Nina becomes CustomerID 1, and Omar becomes 2. The City bike becomes ProductID 20, and the tire tube becomes 21.
Step 3: check the result and total a sample. Sale 5003 has SaleLine (5003, 21, 3). Its value is 3 × 5 = 15. Sale 5004 has (5004, 21, 2), worth 2 × 5 = 10. Together the tube sales are 15 + 10 = 25, matching the original table.
Now change the tube price from 5 to 6 in one cell of the Product table. Every future report uses the new price, and no row needed hunting down.
One more careful point: sales already made should keep the price at that time. Real systems store the price on the SaleLine too, since history must not change when a price list does. This is a good example of a place where a repeated fact is correct on purpose. Normalization is a guide for tidiness, not a ban on ever copying a value.
Before: 3 rows, tube name and price stored twice, Nina stored twice
After: Customer(2 rows) Product(2 rows) Sale(3 rows) SaleLine(3 rows)
Tube sales value: 3 × 5 + 2 × 5 = 15 + 10 = 25 A common mistake
The most common mistake is over-copying: putting a customer's name inside every sale "to make reports easier." It feels harmless until the name changes. The opposite mistake is over-splitting into dozens of tiny tables that no one can follow. Aim for clarity. Each table should answer the question, "What one kind of thing is this a list of?"
Another trap is mixing up a stored total and a calculated one. An invoice total can be calculated from its lines. If you also store it, make sure the system updates it, or leave it out. The next lesson, querying data with SQL basics, shows how to calculate such totals on demand.
Where models lead
A good model makes everything after it easier. Reports are simple to write, controls have obvious places to sit, and an auditor can read the diagram and understand the system. It also helps when you pick software: ask the vendor for its data model, and you learn more than from the sales brochure. Later, in enterprise resource planning systems, you will see one giant model shared by every department.
Words to know
Data model a plan of the entities a business tracks, their attributes and the links between them.
Entity a kind of thing the business keeps facts about, which becomes a table.
Attribute one fact about an entity, which becomes a column.
Cardinality how many rows on one side of a relationship can match rows on the other side.
Entity-relationship diagram (ERD) a drawing of entities as boxes and relationships as lines.
Normalization the process of reorganizing tables to remove repeated and tangled facts.
REA model a design approach built on resources, events and agents.
Check yourself
- Write the relationship between Customer and Sale as a plain sentence, then name the one side and the many side.
- What problem does a cell reading "Tube, Pump, Lock" cause, and which normal form does it break?
- A SaleLine row has SaleID 5004, ProductID 21 and Qty 2, and the tube costs 5. What is the line's value, and what does 5004 total if it has only this line?
- Explain why ProductName does not belong in the SaleLine table.
- In the REA model, classify these: cash, a customer, a sale.
- Why might a system correctly store the price on SaleLine even though Product already has a price?
Show the answers
- One customer places many sales; Customer is the one side and Sale is the many side.
- It packs several values into one cell, so you cannot count or search items; it breaks first normal form.
- 2 × 5 = 10; sale 5004 totals 10.
- It depends only on ProductID, which is part of the key, so storing it on each line repeats it; it belongs in Product.
- Cash is a resource, a customer is an agent, and a sale is an event.
- The price on the day of sale must stay as it was, even if the price list later changes, so the history is correct.