The "revenue by city" report counts one customer in two cities. The orders table carries a copy of the customer's city, added years ago "to save a join". When the customer moved from Aswan to Alexandria, the profile screen updated the customer and their pending orders, since those still had to ship. In a test on SQL Server 2022 with 500,000 orders, that one change left customer 165 with 1 order in Alexandria and 9 in Aswan, and the report split their 5,903.00 in revenue across both cities. Nobody wrote a wrong value. The schema simply allowed two answers to one question.
The common misconception
The belief: exists to save disk space, a habit from when disks were expensive, and denormalizing always makes reads faster because joins are slow.
There's truth in both halves, which is why the belief sticks. In the test, the normalized tables reserved about 50 MB and the flat orders table about 107 MB, and Microsoft's own description of normalization says redundant data wastes disk space. Joins appear as costly operators in execution plans, NoSQL guides say to store data that's read together in one place, and dashboards built on flat tables feel fast. But that same Microsoft sentence goes on: redundant data also creates maintenance problems, because data stored in more than one place must be changed in exactly the same way in all of them. That second part is the real reason normalization exists.
What actually happens
Every copy is a place to be wrong
An happens when a fact lives in many rows and an update misses some of them, so the database contradicts itself. That's what the city report showed. It has two siblings. An insertion anomaly means you can't record one fact without another: a flat orders table has nowhere to store a customer who hasn't ordered yet. A deletion anomaly means removing one fact erases another: archive a customer's old orders and you may delete the only copy of their email.
Normal forms remove those places
Each normal form moves a fact into the table whose key it depends on, so it's stored exactly once. First normal form removes repeating groups, like the Vendor Code 1 and Vendor Code 2 fields in Microsoft's example. Second normal form removes columns that depend on only part of a compound key. Third normal form removes columns that depend on something other than the key, like an advisor's room number stored with each student. Microsoft calls third normal form the highest level necessary for most applications, and adds that if you break the first three rules, your application has to anticipate redundant data and inconsistent dependencies.
Denormalized isn't automatically faster
Copying customer columns into every order made each row wider, so the same 500,000 orders filled four times as many pages. Queries that don't need the copies pay for them anyway. Fetching one customer's latest orders with their name cost 3 extra page reads for the join. The flat table did win one test: revenue by city, where it skipped a join over every order.
Test (500,000 orders, cached)
Normalized
Flat (customer copied)
Space reserved
50 MB
107 MB
Revenue by status, full scan
2,671 reads, 64–80 ms CPU
10,912 reads, 72–84 ms CPU
Revenue by city
3,415 reads, 115–146 ms CPU
10,912 reads, 72–92 ms CPU
A customer moves city
1 row updated
10 rows, or a split report
Denormalize like a cache
When a read really needs a flat shape, keep the normalized tables as the single source of truth and derive the copy from them. Microsoft's Materialized View pattern describes exactly that: a is a read-only projection that's completely disposable because it can be rebuilt from the source, refreshed on an event or a schedule, and possibly stale in between. Analytics models denormalize on the same terms: Power BI's star schema guidance says one denormalized table per dimension generally beats several normalized ones, and those tables are loaded by a refresh, not edited row by row. Inside SQL Server, an indexed view is a copy the engine maintains for you in the same statement that changes the source.
SQL
-- Customer facts copied into every orderCREATE TABLE dbo.OrdersFlat ( Id int PRIMARY KEY, CustomerId int NOT NULL, CustomerCity nvarchar(50) NOT NULL, Status varchar(10) NOT NULL, Total decimal(10,2) NOT NULL);-- Moving a customer must find every copyUPDATE dbo.OrdersFlat SET CustomerCity = N'Alexandria'WHERE CustomerId = 165 AND Status = 'Pending';-- Tested: 1 of 10 rows updated, one customer in two cities
SQL
-- The city lives once, in dbo.Customers; the report is derivedCREATE VIEW dbo.RevenueByCity WITH SCHEMABINDING ASSELECT c.City, SUM(o.Total) AS Revenue, COUNT_BIG(*) AS OrdersFROM dbo.Orders AS o JOIN dbo.Customers AS c ON c.Id = o.CustomerIdGROUP BY c.City;GOCREATE UNIQUE CLUSTERED INDEX IX_RevenueByCity ON dbo.RevenueByCity (City);UPDATE dbo.Customers SET City = N'Alexandria' WHERE Id = 165;-- Tested: 1 row changed, the view moved all 10 orders in the-- same statement, and the report now reads 2 pages
The indexed view gave the report its flat shape without a second source of truth: the city report read 2 pages instead of 3,415, and the move updated the Alexandria and Aswan totals together. The price moves to writes. Every change to Orders or Customers now maintains the view too, and Microsoft warns that many or complex indexed views can degrade write performance significantly. On Standard edition, you also need the NOEXPAND hint to read the view directly.
How to apply it in your project
Find copied factsLook for columns that repeat a value owned by another table, like customer details on orders. A query such as GROUP BY CustomerId HAVING COUNT(DISTINCT CustomerCity) > 1 shows where copies already disagree.
Separate current facts from snapshotsFor each copy, ask whether it should follow the source or freeze at a moment. Move current facts to the table whose key they depend on, and keep snapshots like the price at checkout.
Measure before you denormalizeIndex the join keys first, then compare page reads and CPU with SET STATISTICS IO, TIME ON. In the test, the join for one customer cost 3 page reads, which rarely justifies a copy.
When you do denormalize, derive itUse an indexed view, a materialized view or a projection with one writer and a rebuild path. Decide how stale it may get, and monitor that.
Key takeaways
Normalization stores each fact once so that an update can't leave the database contradicting itself; smaller tables are a bonus.
Update, insertion and deletion anomalies are what redundancy costs you, long before disk space does.
Denormalized tables are wider: in the test, they made a full scan read four times the pages, while making one join-heavy report faster.
Keep normalized tables as the source of truth and treat flat shapes as derived, rebuildable caches.
Copies that record history, like the price at checkout, are facts of their own, not redundancy.
التعليقات (0)