0
0
SQLquery~20 mins

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

Choose your learning style9 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.