Advertisement
Advanced SQL Server, Data Types & Schema Design

What factors should guide the decision to denormalize a schema for performance reasons, and what tradeoffs come with that decision?

Short answer

You might denormalize by duplicating some data across tables to avoid expensive joins in frequently run, performance critical queries, but this comes with the tradeoff of needing to keep the duplicated data synchronized whenever the original value changes, which adds complexity…

Save SQL Server mock interview
Advertisement
AModel answer
You might denormalize by duplicating some data across tables to avoid expensive joins in frequently run, performance critical queries, but this comes with the tradeoff of needing to keep the duplicated data synchronized whenever the original value changes, which adds complexity and the risk of inconsistent data if not carefully managed.
-- Denormalized example: storing a customer's name directly on the order
-- to avoid a join for a frequently run reporting query
CREATE TABLE Orders (
  OrderId INT PRIMARY KEY,
  CustomerId INT,
  CustomerNameSnapshot VARCHAR(100)
);
Real-world example
A reporting heavy application stores a snapshot of the customer's name directly on each order record, avoiding a join for a report that runs thousands of times a day, while accepting the small added complexity of that duplicated data.
Likely follow-ups
  • How do you keep denormalized data consistent when the original source data changes?
  • What is a reasonable process for deciding when denormalization is actually worth the tradeoff?
Related topics