📖 Scenario: You work for a small online bookstore. The database currently has separate tables for Books and Authors. To speed up some common queries, you want to practice denormalization by combining some data into one table.
🎯 Goal: Build a denormalized table that combines book titles and author names into one table for faster reading queries.
📋 What You'll Learn
Create a Books table with columns BookID, Title, and AuthorID.
Create an Authors table with columns AuthorID and Name.
Create a denormalized table BooksWithAuthors that includes BookID, Title, and AuthorName.
Insert sample data into Books and Authors.
Use a SQL query to populate BooksWithAuthors by joining Books and Authors.
Understand when denormalization is helpful for faster reads.
💡 Why This Matters
🌍 Real World
Denormalization is used in real-world databases to speed up queries that read data frequently, such as reporting or dashboards.
💼 Career
Database developers and administrators often decide when to denormalize data to improve performance while balancing data consistency.
Progress0 / 4 steps
1
Create the Books and Authors tables
Write SQL statements to create a table called Books with columns BookID (integer primary key), Title (text), and AuthorID (integer). Then create a table called Authors with columns AuthorID (integer primary key) and Name (text).
SQL
Hint
Use CREATE TABLE statements with the exact column names and types.
2
Insert sample data into Books and Authors
Write SQL INSERT statements to add these entries: In Authors, add (1, 'Jane Austen') and (2, 'Mark Twain'). In Books, add (101, 'Pride and Prejudice', 1) and (102, 'Adventures of Huckleberry Finn', 2).
SQL
Hint
Use INSERT INTO with exact values for authors and books.
3
Create the denormalized BooksWithAuthors table
Write a SQL statement to create a new table called BooksWithAuthors with columns BookID (integer primary key), Title (text), and AuthorName (text).
SQL
Hint
Use CREATE TABLE with the specified columns for the denormalized table.
4
Populate BooksWithAuthors by joining Books and Authors
Write a SQL INSERT INTO BooksWithAuthors statement that selects BookID, Title, and Name as AuthorName by joining Books and Authors on AuthorID.
SQL
Hint
Use INSERT INTO ... SELECT ... JOIN to combine data from both tables.
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
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.
Final Answer:
To add redundant data to speed up read operations -> Option D
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
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.
Final Answer:
A table with repeated customer address fields in each order record -> Option B
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
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.
Final Answer:
You must update the address in every order row for that customer -> Option A
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
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.
Final Answer:
The WHERE clause did not match all rows for CustomerID 5 -> Option A
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
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.
Final Answer:
Add customer name and address columns directly into the Orders table -> Option C
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 unknownstrongwhile earning +1 Grip toward your certificate.