Achieving Third Normal Form (3NF): Walkthrough and Examples

UPI Study › Courses › Database Programming › Free lessons › Lesson 2.4 Free with a free account

Achieving Third Normal Form (3NF): Walkthrough and Examples

Database Programming · Chapter 2: Normalization and Data IntegritySection 2.4 · lesson 11 of 7610 min · free with a free account

← Breaking Down First Normal Form (1NF) with ExamplesNext lesson: Primary Keys in SQL: What They Are and How to Use Them →

A free account plays all of Chapter 1 and 3 more lessons of Database Programming. Create a free account →

Earn 3 college credits for Database ProgrammingRecommended for credit by NCCRS · Computer Science 381 · self-paced · one payment, lifetime access

In this lesson

Find transitive dependencies and split tables while keeping their links.

  • Define a transitive dependency and the formal third normal form rule
  • Split a table into second and then third normal form step by step
  • Keep determinants as foreign keys so joins can rebuild the original rows
  • Test a design by repeating update, insertion, and deletion scenarios

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (1,224 words). Read along, or search it.

Opening Problem

Renaming Sales in Two Records

Owner Maya and developer Leo both work in Sales in this fictional staff example. If Sales changes its name, why should two staff records need editing? The staff identifier already makes each row unique. A single-column key did not stop us from storing department facts beside every employee. The problem is a dependency chain, and third normal form gives us a repair. We will carry the same idea through our bookstore design.

Definition

Transitive Dependencies and the Formal Rule

A transitive dependency is a chain: staff identifier determines department identifier, which determines department name. The final fact describes the department. For our simple one-key designs, third normal form means second normal form without those non-key-to-non-key chains. Formally, each nontrivial dependency needs a superkey determinant or a prime dependent attribute. A prime attribute belongs to some candidate key. Second normal form considers every candidate key. Its single-column shortcut applies when all candidate keys are single-column, as in this staff example.

Anomalies

Department Names Stored Twice

The department identifier determines its name. Staff identifier determines department identifier, so a department name is repeated through a transitive chain. Renaming Sales risks inconsistent copies. A new empty department cannot be represented, and deleting its last staff member can erase the department. A determinant is the value that fixes another value. Here, department identifier belongs at the center of a separate department relation. Run the staff example, and inspect which values repeat. We are looking for a dependency problem, rather than duplicate whole rows. Both staff names share department ten and Sales. The staff identifiers differ, but the same department description has two storage locations.

Repair

A Separate Departments Table

Move department identifier and name into Departments. Department identifier becomes the key, and Staff retains it as a foreign key. Retaining the middle of the chain preserves membership. Removing that identifier from Staff would lose which department each employee belongs to. Training can now exist without employees. Updating Sales to Retail changes one department row; both staff references still reach it. Run the repaired design, then join staff to departments by their shared identifier. The name change applies through the relationship. Maya and Leo both display Retail. Their records needed no copied department-name edits, and Training remains independent of staffing.

Bookstore Stages

From Packed Sheet to First Normal Form

Now expand a disposable subset of Lantern Books. We add a category to each product, without changing the course's canonical baseline. The unnormalized sheet packs products into one cell. First normal form gives each product on an order its own row, with separate quantity. The candidate key is order and product together. Order date and customer details repeat per item; product and category descriptions repeat across orders. Our category assignments are invented design examples. Database Basics is Technical, Notebook is Supplies, and World History is Humanities.

Finding Dependencies

Second and Third Normal Form Splits

Order identifier fixes date and customer, so those facts depend on only part of the order-product key. Product identifier fixes product name and category identifier. That is another partial dependency; quantity needs the entire pair. Second normal form separates Orders, Products, and OrderItems. Customer city still depends on customer identifier inside Orders; category name depends on category identifier inside Products. Third normal form splits those two chains into Customers and Categories. Their identifiers stay behind as links in Orders and Products.

Final Schema

Five Tables and Their Links

The final schema has five subjects. Customers identify people, and Categories identify the shop's product groups in this extension. Products keep category identifier, while Orders keep customer identifier. Each order belongs to one customer; a customer may have several orders. OrderItems keeps both order and product identifiers. Each order can have several lines, and each product can appear on several orders. Quantity belongs to the pair. The composite key enforces our one-line-per-product-per-order rule, while foreign keys preserve each connection.

Loading Data

Parents Before Dependent Rows

The data loader starts by reading the schema. Dot read is a SQLite shell command, so this file runs through the shell. Parents are supplied before dependent rows: customers and categories, then products and orders, followed by the order items. Order five thousand one contains Database Basics and two notebooks. Ben's order five thousand three contains World History. These are the same identifiers and quantities from our shared course data, with the category extension clearly separated from the baseline.

Reconstruction

Joining Five Tables Back Together

A join combines rows wherever its matching condition is true. Here, each child identifier is matched to the parent key it references. Read the aliases as short names for the five tables. Each match follows a retained link, rather than guessing from a person's name. A lossless decomposition reconstructs exactly the original legal rows. Our expected subset has three item rows, with the original customers, categories, and quantities. Run the reconstruction, ordered by order and product. This is a first reading of joins; their full query syntax comes later. The three reconstructed lines match our starting facts. Asha's two lines and Ben's single line remain attached to their original orders.

Anomaly Tests

City Change, New Category, Canceled Order

Audit each relation by naming its key and asking what determines the other columns. Only OrderItems needs a composite key in this design. Repeat the anomalies: change Asha's city once, add Poetry without a product, and cancel Ben's order without deleting Ben. Each operation changes the intended fact. Deleting the order lines before their header respects the relationships during removal. Run those tests in a fresh copy, then inspect the surviving customer and category facts. The baseline database remains untouched. Asha now has Mumbai, Ben still exists, and Poetry exists without a product. These are the independent facts the mixed sheet struggled to represent.

Quick Check

Following the Supplier Link to Oslo

A separate delivery system moves supplier city into Suppliers. Deliveries keeps supplier identifier, and the displayed query follows that identifier. What does the query return: Oslo, no city, or a foreign key error? Decide whether the retained link is sufficient. Pause, and predict the result from this new supplier example. Oslo is the answer. Supplier identifier remains in Deliveries, so the query reaches the supplier row that owns the city. Run the lookup, following the retained identifier. Moving the description did not remove the relationship between a delivery and its supplier. Oslo appears once. The missing-city and error options confuse relocating a fact with discarding its identifying link.

Design Audit

Confirm Dependencies Against Business Rules

Do not invent dependencies from coincidental rows. Confirm each one against the business rule. Third normal form is a useful business-design target. Boyce-Codd may require more; a slow report may justify a separate measured read model. Keep normalized data authoritative, and document any duplicated report's refresh process. A stale copy can recreate the consistency problems we removed.

Quick Check

Two Visitors Named Mira

A separate visitor log has two people named Mira, with different identifiers and cities. The name column has no uniqueness rule. What does selecting cities for Mira return: the later city, no city, or both cities? Pause, and predict. Lagos and Leeds both appear. The shared name is not the key, and both independently identified rows satisfy the condition. Run the query to check the proposed name-to-city dependency. One legal counterexample is enough to disprove it. The result contains both cities. Choosing the later row would invent a selection rule that the statement never specified.

Key Takeaways

Move the Chain, Keep the Link

Find the transitive chain, move its descriptive facts, and retain the determinant as the link. That is the practical repair we used. Remove partial dependencies before transitive ones. Our order sheet became customers, orders, order items, products, and categories, with the same original facts. Validate the design by auditing keys, reconstructing the rows, and repeating ordinary changes. Separate subjects should remain independent when their related activity disappears.

About Database Programming at UPI Study

Database Programming (Computer Science 381) is a self-paced online course of 76 video lessons in 12 chapters, from database applications, SQL setup, schema planning and normalization to keys and constraints, data types, filtering and sorting, joins, subqueries, views, indexes, ROLLUP and PIVOT, regular expressions and database security. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Database Fundamentals vs Database Programming

Why take it here

Why students take Database Programming with UPI Study

Write the SQL behind every appDatabase Programming teaches SQL in MySQL and SQL Server side by side: designing and normalizing tables, keys and constraints, data types, inserting, updating and deleting rows, filtering, grouping, joins, subqueries, views, indexes, transactions, and protecting data from SQL injection. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Database Programming carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About Achieving Third Normal Form (3NF): Walkthrough and Examples

What is a transitive dependency?
A transitive dependency is a chain in which a key determines a non-key column, and that column determines another non-key column. If staff_id determines department_id, and department_id determines department name, the name depends on staff_id through the department. Storing it beside each employee repeats it, so renaming a department means editing several rows, and deleting the last employee can erase the department.
How do you convert a table to third normal form?
Reach first normal form, remove partial dependencies to reach second, and then move each transitive chain into its own table. For each chain, place the determinant and the facts it fixes in a new table keyed by that determinant, and leave the determinant behind as a foreign key. Then verify the design by joining the tables back together and repeating insert, update, and delete tests.
Why keep the foreign key column when splitting a table for 3NF?
The foreign key preserves the relationship that the split would otherwise lose. If department name moves to a departments table and department_id is also removed from staff, nobody can tell which department each employee belongs to. Keeping department_id in staff lets a join reconstruct the original rows, and one rename in departments then reaches every employee who references that department.
What does a third normal form schema for an online store look like?
A common 3NF store design separates customers, orders, order items, products, and categories. Orders keep customer_id, products keep category_id, and order items keep both order_id and product_id, often as a composite key, with quantity stored on that pair. Customer city then lives once in customers and category names once in categories, so a city change, a new empty category, or a canceled order each affects one intended fact.

About the Database Programming course

How many college credits is Database Programming?
Database Programming (Computer Science 381) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Database Programming cost and what is included?
$250, paid once, with lifetime access: all 76 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Database Programming take?
It is self-paced with no deadlines. The 76 lessons total about 11 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Database Programming.

76 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Database Programming
3 credits · NCCRS
Enroll →