ACCT 320 · Accounting Information Systems

Relational Databases for Accountants

A relational database splits facts into linked tables so each fact is stored once, which keeps accounting records accurate and easy to search.

Key takeaways

  • A relational database stores data in tables made of rows (records) and columns (fields), and links tables through shared keys.
  • A primary key uniquely identifies each row; a foreign key in another table points back to it.
  • Storing each fact once avoids update, insert and delete problems that a single big sheet causes.
  • Links between tables come in three shapes: one-to-one, one-to-many and many-to-many.
  • A database management system (DBMS) is the program that stores the data and enforces rules, so bad data is refused.

Rosa at Spoke & Mirror keeps her sales in one big spreadsheet. Every row holds the date, the customer's name, the customer's phone number, the bike, the price, and the payment type. It works for a month. Then a regular customer, Nina, changes her phone number. Nina has bought 14 times, so her old number sits in 14 rows. Rosa fixes 11 of them and misses 3. Now the sheet claims Nina has two phone numbers, and nobody knows which is right.

This is the kind of mess a relational database was invented to prevent. The idea is simple: store each fact in exactly one place, and link places together. This lesson shows how that works, in words an accountant can use, with Spoke & Mirror as the guinea pig.

Why one big table breaks

Look closely at Rosa's spreadsheet problem. A big flat table repeats facts, and repeated facts cause three kinds of trouble.

  • Update trouble. Change a fact in one row and forget the others, and you have conflicting versions. That was Nina's phone number.
  • Insert trouble. You cannot record a new customer until she buys something, because the table only has sale rows. A new customer has no place to live.
  • Delete trouble. If Rosa deletes the only sale a customer ever made, she also erases the customer's name and phone.

All three come from mixing different kinds of facts in one place. Facts about customers, facts about products and facts about sales are different things. The cure is to give each its own table.

Tables, rows and columns

A table holds facts about one kind of thing. Each row (also called a record) is one instance, such as one customer. Each column (also called a field) is one fact about every instance, such as phone number.

Here is a tiny Customers table for the bike shop.

CustomerID Name Phone
1 Nina Park 555-0142
2 Omar Reyes 555-0177
3 Tessa Cole 555-0119

Nina's phone number now lives in exactly one cell. Change it once, and every sale she ever made reflects the new number, because the sales do not copy it. They only point to her.

How does a sale point to Nina? Through keys.

A primary key is a column (or set of columns) whose value is different in every row, so it names exactly one row. CustomerID is the primary key of Customers. Names would be a poor choice, since two customers can share one. That is why systems invent ID numbers.

A foreign key is a column in one table that holds the primary key of another table. It is the link. In the Sales table below, CustomerID is a foreign key that points to a row in Customers.

SaleID Date CustomerID ProductID Price
5001 Mar 3 1 20 400
5002 Mar 4 2 21 90
5003 Mar 9 1 21 90

Sale 5001 and sale 5003 both carry CustomerID 1, so both belong to Nina. To find Nina's phone, the database looks up customer 1 in the Customers table. No copying needed.

Linked tables at Spoke & Mirror
Many sales Nina Park has sales 5001 and 5003 one customer Customers table One row per customer: ID, Name, Phone Many sales Tire tube 21 is on sales 5002 and 5003 one product Products table One row per product: ID, Name, Cost CustomerID ProductID Sales table One row per sale: SaleID, Date, Price Sales table One row per sale: SaleID, Date, Price CustomerID: Customers table One row per customer: ID, Name, Phone one customer: Many sales Nina Park has sales 5001 and 5003 ProductID: Products table One row per product: ID, Name, Cost one product: Many sales Tire tube 21 is on sales 5002 and 5003

Tables relate in three ways. Accountants meet all three constantly.

One-to-one. One row in A matches at most one row in B. Example: each employee has one payroll tax record. This is rare, and it often means the two tables could simply be one.

One-to-many. One row in A matches many rows in B, but each row in B matches only one in A. Example: one customer has many sales, but each sale belongs to one customer. This is by far the most common shape. The "many" side holds the foreign key.

Many-to-many. Many rows in A match many rows in B. Example: one sale can include several products, and one product appears on many sales. A database cannot store this directly. The fix is a middle table, called a junction table, that turns it into two one-to-many links. For Rosa, a SaleLines table holds one row per product per sale: SaleID, ProductID, Quantity. You will design this kind of table in designing data models.

The three shapes of a link
One-to-one One employee, one tax record Rare in practice Often merged into one table One-to-many One customer, many sales Foreign key sits on the many side The most common shape Many-to-many Many sales, many products Needs a junction table Becomes two one-to-many links One-to-one One employee, one tax record Rare in practice Often merged into one table One-to-many One customer, many sales Foreign key sits on the many side The most common shape Many-to-many Many sales, many products Needs a junction table Becomes two one-to-many links

How the accounting records fit

Accounting data has a natural database shape. Take the general ledger, the master list of accounts that you learned in accounts and the chart of accounts. Each entry has a date and a memo, and each entry has two or more lines, each hitting an account for a debit or credit amount.

  • An Accounts table: AccountNumber (primary key), AccountName, Type.
  • A JournalEntries table: EntryID (primary key), Date, Memo.
  • A JournalLines table: LineID, EntryID (foreign key), AccountNumber (foreign key), Debit, Credit.

One entry has many lines, and one account appears in many lines. The line table is the junction between entries and accounts. The rule that debits equal credits becomes a rule the database can check: for every EntryID, the sum of Debit must equal the sum of Credit.

A worked example: finding what a customer owes

Suppose Rosa lets Nina buy on credit. Sales to Nina are in the Sales table, and her payments are in a Payments table with CustomerID as a foreign key. Let us find Nina's balance.

Sales to Nina (CustomerID 1): 400 (sale 5001) and 90 (sale 5003). Total sales = 400 + 90 = 490.

Payments from Nina: one payment of 300. Total paid = 300.

Balance owed: 490 − 300 = 190.

Notice what the database did. It never stored the number 190 in one place and hoped it stayed right. It stored the sales and the payments, and the balance came from them. That is why the number cannot drift out of step with the facts.

Now see how three tables cooperate to print a customer statement: Customers supplies the name and phone, Sales supplies the charges, Payments supplies the credits. One report, three tables, each fact stored once. You will write this very query in querying data with SQL basics.

Nina Park (CustomerID 1)
Sales:      400 + 90 = 490
Payments:             300
Balance owed: 490 − 300 = 190

Rules the database enforces

A database management system (DBMS) is more than a filing cabinet. It enforces rules, and several matter to accountants.

  • Entity integrity. Every row must have a primary key, and no two rows may share one. You cannot have two Customer 1s.
  • Referential integrity. A foreign key must point to a row that exists. A sale for CustomerID 99 is refused if there is no customer 99. Likewise, you cannot delete a customer who still has sales, unless the rule is set to handle that.
  • Data types and limits. A price column accepts only numbers, a date column accepts only dates, and a required column cannot be left blank.

These rules are controls, built into the machinery. They catch typing slips at the door instead of months later. When you study IT general controls and application controls, you will see them again as application controls.

How a database refuses a bad sale
1 Clerk enters a sale Customer 99, product 20, price 400 2 DBMS checks the key Does customer 99 exist in Customers? 3 No match found Referential integrity fails 4 Sale refused A message asks for a valid customer Clerk enters a sale Customer 99, product 20, price 400 1 DBMS checks the key Does customer 99 exist in Customers? 2 No match found Referential integrity fails 3 Sale refused A message asks for a valid customer 4

A common mistake

The most common mistake is using a changeable fact as a key. Suppose Rosa made the customer's name the primary key. Then when "Tessa Cole" marries and becomes "Tessa Ruiz," every sale pointing to her old name breaks, or she must be edited everywhere. A good key never changes and carries no meaning. Use a plain ID number.

A second mistake is storing a calculated number such as a balance as a stored fact, then forgetting to update it. Store the facts that make the number and calculate it when you need it. A third mistake is thinking a spreadsheet with several tabs is a relational database. Tabs can hold tables, but a spreadsheet does not enforce keys or integrity, so nothing stops a bad entry.

Reading a database like an accountant

When someone shows you a database, ask four questions. What are the tables, and what does each row stand for? What is the primary key of each? How are the tables linked? And which rules refuse bad data? Those four answers tell you where a fact is stored, how to find it, and how much to trust it.

This view also helps an auditor. If every sale is tied to a valid customer and product, and every journal entry balances, then totals built from the tables are trustworthy by design. In the general ledger and reporting cycle you will see these tables produce the financial statements.

Words to know

Relational database a collection of linked tables that store each fact once.

Table a grid of rows and columns that holds facts about one kind of thing.

Primary key a column whose value uniquely identifies each row in its table.

Foreign key a column in one table that holds the primary key of a row in another table.

Junction table a middle table that turns a many-to-many link into two one-to-many links.

Referential integrity the rule that a foreign key must match an existing row in the table it points to.

DBMS the database management system, the program that stores data and enforces its rules.

Check yourself

  1. Name two problems caused by storing Nina's phone number in all 14 of her sales rows.
  2. What is the difference between a primary key and a foreign key?
  3. Nina bought 3 times: 400, 90 and 90. She paid 350. How much does she owe?
  4. Why does a many-to-many link between sales and products need a third table?
  5. Explain why a customer's name is a poor primary key.
  6. A sale refers to CustomerID 99, but no such customer exists. Which rule should refuse the sale, and why does that help the books?
Show the answers
  1. Update trouble (changing it in some rows but not others leaves conflicting numbers) and wasted, repeated storage; deleting a customer's only sale can also erase her phone.
  2. A primary key uniquely names a row in its own table; a foreign key sits in another table and holds that key to link back.
  3. Sales 400 + 90 + 90 = 580; minus payment 350 gives 580 − 350 = 230 owed.
  4. A database cannot store a many-to-many link directly; a junction table such as SaleLines splits it into two one-to-many links.
  5. Names can repeat and can change, which would break every link that uses them; a plain ID never changes.
  6. Referential integrity should refuse it, because every sale must tie to a real customer, so no revenue is booked against a person who does not exist.

A free self-study program written for 4Accounting with AI writing tools and not reviewed line by line by a person. It is not an accredited degree and awards no credit. Check anything you rely on against a textbook or primary source. Report an error.

In this unit: Systems foundations

  1. What an Accounting Information System DoesAn accounting information system collects, stores, processes and reports a business's money facts, and it keeps them trustworthy along the way.12 min
  2. Documenting Systems With FlowchartsA flowchart shows each step of a process with standard shapes, so anyone can spot where work stalls, repeats or goes unchecked.10 min
  3. Data Flow and Process DiagramsA data flow diagram shows where information comes from, what changes it, where it rests, and where it goes, without caring about step order.10 min
  4. Relational Databases for AccountantsA relational database splits facts into linked tables so each fact is stored once, which keeps accounting records accurate and easy to search.10 min
  5. Designing Data ModelsA data model plans which things a business tracks and how they link, using entity diagrams and normalization to avoid repeated facts.10 min
  6. Querying Data With SQL BasicsSQL lets you ask a database questions in near-plain English: pick columns, filter rows, join tables, group and total.10 min

In the news