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
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Database Programming.
Lesson complete
Earn the 3 college credits for Database Programming
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Primary Keys in SQL: What They Are and How to Use Them →← 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 →
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.
Enroll now → Course details Download the syllabus All Computer Science courses Every credit course with PRO →
Why take it here
Why students take Database Programming with UPI Study
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.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →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?
How do you convert a table to third normal form?
Why keep the foreign key column when splitting a table for 3NF?
What does a third normal form schema for an online store look like?
About the Database Programming course
How many college credits is Database Programming?
How much does Database Programming cost and what is included?
Which universities accept UPI Study credits?
How long does Database Programming take?
How are the exams done?
How do my credits reach my college?
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
3 credits · NCCRSEnroll →