Making Data Clean: Normalization Rules in SQL, Explained

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

Making Data Clean: Normalization Rules in SQL

Database Programming · Chapter 2: Normalization and Data IntegritySection 2.1 · lesson 8 of 768 min · free with a free account

← Installing Your Database Environment — MySQL and SQL Server Express Setup GuideNext lesson: Understanding Normal Forms: Types and Worked Examples →

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

Spot redundancy and anomalies, then split tables by functional dependencies.

  • Identify redundancy and the update, insertion, and deletion anomalies it causes
  • Explain functional dependencies and test them with counterexamples
  • Decompose a mixed table while keeping identifiers as links
  • Check that a decomposition is lossless by reconstructing the original facts

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 (996 words). Read along, or search it.

Opening Problem

Two Cities for One Customer

Maya Rao owns Lantern Books, our fictional campus bookstore. Asha moves, but two order records now disagree about her city. One says Pune. Another says Mumbai. Which should the shipping team trust, and why did one move require several edits? These are invented teaching records. The problem is their design: customer details have been copied beside orders. Normalization asks where each fact belongs, so the next change has one clear place to happen.

Redundancy

Customer Details Copied Beside Orders

Consider a flattened report from our shop. Order five thousand one belongs to customer one, Asha, in Pune. Order five thousand four also belongs to Asha. Her city is repeated, even though it describes the customer. That unnecessary duplication is redundancy. Repeated descriptive text consumes storage, and one real change now requires coordinated edits. Repeating an identifier is different: customer one appears on several orders because the relationships themselves are different facts.

Update Anomaly

One Move, Several Edits

An update anomaly occurs when one change must be repeated, and a missed copy leaves contradictory data. Asha moves to Mumbai. Changing the city on just one order leaves two answers for the same current address. A careful person might repair every row today. The design still demands that same care from every future program. Keeping current city in one customer record removes this particular synchronization problem. Correct rules and transactions still matter.

Insertion Anomaly

A Book Awaiting Its First Sale

An insertion anomaly blocks a fact because an unrelated fact has not happened. Imagine a new book awaiting its first sale. If every row requires an order, where can the shop record that book? Inventing an order would create false business data. A separate products table can hold the book before any customer buys it. A customer can likewise register without ordering. The goal is independent existence for independent subjects, rather than forcing every new fact into an order record.

Deletion Anomaly

Canceling an Order Erases Ben

A deletion anomaly destroys one fact while intentionally removing another. Ben has only one order in our disposable example. If his details exist only beside that order, deleting the canceled order also erases the customer record. Separate customers from orders, and canceling the order leaves Ben available for a future purchase. Deliberate retention and privacy policies need their own rules. They decide what the shop should intentionally keep or remove.

Functional Dependency

Customer Identifier Determines Current City

A functional dependency says that knowing one set of values fixes another, across every legal state of the data. Customer identifier determines current city, if our business rule gives each customer one current city. The identifier is the determinant. We read the relationship as customer identifier determines city. Two customers can share a city, so reversing that relationship fails. The rule concerns meaning, not spelling. Customer names are unsafe determinants when different people can share a name.

Testing Dependencies

Counterexamples Disprove a Dependency

A primary key identifies a row uniquely. Order identifier therefore determines the customer and date recorded for that order. Customer identifier does not determine order identifier: Asha can place several different orders. Product identifier determines current catalog price under our stated shop rule. It does not determine quantity on every order. A counterexample disproves a dependency. Matching sample rows cannot prove it; ask whether a future legal row could differ.

Naming the Fact

Catalog Price Versus Price Charged

A catalog price describes today's offer. A price charged describes one completed sale, and those are different facts. Changing the catalog must not rewrite an old invoice. Historical sale price therefore belongs with the sale information. Normalization removes unnecessary copies of the same fact. It does not forbid repeated values or require erasing legitimate history. Before splitting anything, name the fact precisely. Current price and charged price lead to different dependency rules.

Decomposition

Separate Homes for Customers and Products

Decomposition means splitting a relation into smaller relations. Start with customer facts in customers, identified by customer identifier. Product facts belong in products, including the current catalog price. This gives each product one independent home. Orders keep the date and customer identifier. They link to customer facts, instead of copying the city. Order items connect orders to products and hold quantity. One product appears once per order, so the identifier pair identifies each line.

Lossless Joins

Keeping Identifiers as Links

Keep customer identifier in orders as a link. Without that column, separating customer details would also lose who placed each order. Keep both identifiers in order items, so every line can still find its order and product. A join combines matching rows. A lossless split lets those joins reconstruct exactly the original legal facts, without omissions or invented combinations. More tables alone do not prove a better design. The dependencies and the preserved connections justify the split.

Quick Check

The Vanishing Publisher Phone Number

Amina Diallo, the shop's database administrator, reviews a new design for publisher contacts. Publisher phone is stored only beside each product. The last product from one publisher is removed, and its contact number disappears. Which failure occurred: an insertion anomaly, an update anomaly, or a deletion anomaly? Pause, and decide. Deletion anomaly is the answer. Removing a product also removed the only stored fact about its publisher. An update anomaly would need conflicting edits. An insertion anomaly would prevent adding a publisher before a product exists. Give publishers their own table, and retain publisher identifier in products. Now a publisher can survive the removal of its last product.

Workflow

Facts, Dependencies, Split, Then Test

Find the facts and write the dependencies first. Ask the people using the data which rules must remain true. Split by those rules, then link the resulting tables using identifiers. Normal forms provide staged tests for these choices. Check the reconstruction, then repeat the insertion, update, and deletion scenarios. Make sure each repair preserves intended relationships. Joins add work when reading. Measure real performance before deliberately duplicating facts, and document how any copies stay synchronized.

Key Takeaways

One Clear Home for Each Fact

Redundancy means unnecessary repeated facts. Normalization reduces the storage and maintenance costs that come with those copies. Insertion, update, and deletion anomalies reveal different ways a mixed table can fail during ordinary work. Functional dependencies express business rules. A sample can expose a broken rule, but it cannot establish the rule for tomorrow. A useful decomposition preserves the links and passes the lossless reconstruction test. Maya can change Asha's current city in one customer record.

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 Making Data Clean: Normalization Rules in SQL

What is normalization in database design?
Normalization is a design process that gives each fact one clear home, reducing redundancy and the anomalies it causes. A table that copies a customer's city beside every order can end up showing two cities for one customer. Normalization writes down the functional dependencies, splits mixed tables into focused ones such as customers, products, and orders, and keeps identifiers as links so joins can rebuild the original facts.
What are update, insertion, and deletion anomalies?
They are three ways a table that mixes different facts fails during ordinary work. An update anomaly means one real change must be repeated, so a missed copy leaves contradictory data. An insertion anomaly blocks a fact until an unrelated fact exists, such as a book that cannot be recorded before its first sale. A deletion anomaly erases one fact while removing another, such as losing a customer by deleting their single order.
What is a functional dependency in a database?
A functional dependency means that knowing one set of values fixes another value in every legal state of the data. If each customer has one current city, customer_id determines city, and customer_id is the determinant. The reverse fails, because two customers can share a city. Sample rows can disprove a dependency with a counterexample, but they cannot prove one; the business rules decide it.
Does normalization mean a value should never be repeated?
No, normalization removes unnecessary copies of the same fact, not every repeated value. A customer identifier appears on many orders because each order is a different relationship fact. The price charged on an old sale is also a separate fact from today's catalog price, so it belongs with the sale and should not change when the catalog changes. Name each fact precisely before deciding whether a repeat is redundant.

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 →