Bird
Raised Fist0
SQLquery~20 mins

Denormalization and when to use it in SQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Denormalization Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why choose denormalization in a database?
Which of the following is the main reason to use denormalization in a database design?
ATo reduce the number of joins and improve read query performance
BTo eliminate data redundancy completely
CTo enforce strict data integrity through foreign keys
DTo make the database schema more complex and normalized
Attempts:
2 left
💡 Hint
Think about what happens when you want faster data retrieval at the cost of some redundancy.
❓ query_result
intermediate
2:00remaining
Output of a denormalized query
Given these two tables:

Customers(customer_id, name)
Orders(order_id, customer_id, order_date)

We create a denormalized table:
CustomerOrders(customer_id, name, order_id, order_date)

What will be the output of:
SELECT customer_id, name, COUNT(order_id) AS order_count FROM CustomerOrders GROUP BY customer_id, name;
AAn error because of missing GROUP BY columns
BA list of customers with the count of their orders
CA list of orders with duplicated customer names
DA list of customers with total order amounts
Attempts:
2 left
💡 Hint
Grouping by customer_id and name counts orders per customer.
📝 Syntax
advanced
1:30remaining
Identify the error in denormalized table update
Consider a denormalized table storing product info and category name:

Products(product_id, product_name, category_id, category_name)

Which SQL statement will cause an error when updating category_name for all products in category 5?
SQL
UPDATE Products SET category_name = 'New Category' WHERE category_id = 5;
AUPDATE Products SET category_name = 'New Category' WHERE category_name = 5;
BUPDATE Products SET category_name = 'New Category' WHERE product_id = 5;
CUPDATE Products SET category_name = 'New Category';
DUPDATE Products SET category_name = 'New Category' WHERE category_id = 5;
Attempts:
2 left
💡 Hint
Check the data types in the WHERE clause.
❓ optimization
advanced
2:00remaining
Optimizing read performance with denormalization
You have a normalized database with tables for Users, Orders, and Products. You want to speed up a report that shows user names, order dates, and product names. Which denormalization strategy will best improve read speed?
AAdd indexes on foreign keys in all tables
BRemove all foreign keys to speed up inserts
CCreate a denormalized table combining user name, order date, and product name
DSplit the Orders table into smaller tables by date
Attempts:
2 left
💡 Hint
Denormalization duplicates data to avoid joins in queries.
🔧 Debug
expert
2:30remaining
Troubleshooting stale data in denormalized tables
You have a denormalized table storing customer info and their latest order date. After updating the Orders table, the denormalized table shows old order dates. What is the most likely cause?
AThe Orders table has a foreign key constraint preventing updates
BThe database engine does not support denormalization
CThe denormalized table has a syntax error in its definition
DThe denormalized table is not updated automatically after Orders change
Attempts:
2 left
💡 Hint
Denormalized data must be refreshed or updated manually or via triggers.

Practice

(1/5)
1. What is the main purpose of denormalization in a database?
easy
A. To split data into many small tables
B. To remove all duplicate data for storage efficiency
C. To enforce strict data integrity rules
D. To add redundant data to speed up read operations

Solution

  1. Step 1: Understand denormalization goal and compare options

    Denormalization means adding repeated data to reduce complex joins and speed up reading. Only "To add redundant data to speed up read operations" describes adding redundant data to improve read speed, which matches denormalization.
  2. Final Answer:

    To add redundant data to speed up read operations -> Option D
  3. Quick Check:

    Denormalization = add redundant data for faster reads [OK]
Hint: Denormalization means adding data to read faster, not removing it [OK]
Common Mistakes:
  • Confusing denormalization with normalization
  • Thinking denormalization removes duplicates
  • Believing denormalization enforces stricter rules
2. Which of the following best represents a denormalized table structure?
easy
A. Separate tables for customers and orders linked by customer_id
B. A table with repeated customer address fields in each order record
C. A table with only unique keys and no repeated data
D. A table with foreign keys but no repeated columns

Solution

  1. Step 1: Identify denormalized structure and match to options

    Denormalized tables store repeated data, like customer address repeated in each order. "A table with repeated customer address fields in each order record" shows repeated fields in one table, which is denormalization. Others show normalized forms.
  2. Final Answer:

    A table with repeated customer address fields in each order record -> Option B
  3. Quick Check:

    Repeated fields in one table = denormalized [OK]
Hint: Look for repeated fields in one table to spot denormalization [OK]
Common Mistakes:
  • Choosing normalized table structures
  • Confusing foreign keys with denormalization
  • Ignoring repeated data presence
3. Given a denormalized table Orders with columns OrderID, CustomerName, and CustomerAddress repeated in every row, what is a likely effect when updating a customer's address?
medium
A. You must update the address in every order row for that customer
B. Updating one row automatically updates all related rows
C. No update is needed because address is stored separately
D. The database prevents duplicate addresses

Solution

  1. Step 1: Understand denormalized update effects and analyze options

    In denormalized tables, repeated data means updates must be applied to all copies to keep consistency. Only "You must update the address in every order row for that customer" correctly states that all rows must be updated manually.
  2. Final Answer:

    You must update the address in every order row for that customer -> Option A
  3. Quick Check:

    Repeated data requires multiple updates [OK]
Hint: Repeated data means multiple updates needed for consistency [OK]
Common Mistakes:
  • Assuming one update changes all rows automatically
  • Thinking address is stored separately in denormalized tables
  • Believing database prevents duplicates in denormalized data
4. You have a denormalized table where customer phone numbers are repeated in many rows. You run this update:
UPDATE Orders SET CustomerPhone = '123-4567' WHERE CustomerID = 5;
but some rows still show old phone numbers. What is the most likely problem?
medium
A. The WHERE clause did not match all rows for CustomerID 5
B. Denormalization prevents updates to repeated data
C. CustomerPhone is a computed column and cannot be updated
D. The database automatically updates all rows, so this is impossible

Solution

  1. Step 1: Analyze update query symptom and identify cause

    The update targets rows with CustomerID = 5, but some rows still have old data, meaning some rows were missed. Most likely, some rows have incorrect or missing CustomerID values, so the WHERE clause did not match them.
  2. Final Answer:

    The WHERE clause did not match all rows for CustomerID 5 -> Option A
  3. Quick Check:

    Update misses rows if WHERE condition is incomplete [OK]
Hint: Check WHERE clause matches all repeated rows in denormalized tables [OK]
Common Mistakes:
  • Thinking denormalization blocks updates
  • Assuming computed columns without checking
  • Believing database auto-updates all duplicates
5. You want to speed up reporting queries that join Orders and Customers tables frequently. Which denormalization approach is best to improve read speed while managing data consistency?
hard
A. Remove customer details from Orders and query Customers each time
B. Keep separate tables and add more indexes on join keys
C. Add customer name and address columns directly into the Orders table
D. Duplicate Orders table for each customer

Solution

  1. Step 1: Identify denormalization for faster reads and evaluate options

    Adding customer info directly into Orders reduces joins, speeding up queries. "Add customer name and address columns directly into the Orders table" adds repeated data for speed and requires careful updates, fitting denormalization best.
  2. Final Answer:

    Add customer name and address columns directly into the Orders table -> Option C
  3. Quick Check:

    Denormalize by adding repeated data to reduce joins [OK]
Hint: Denormalize by adding repeated fields to reduce joins for faster reads [OK]
Common Mistakes:
  • Thinking indexing replaces denormalization
  • Removing data increases joins and slows queries
  • Duplicating entire tables causes complexity
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard