📖 Scenario: You are working for a small bookstore that wants to organize its sales data efficiently. Currently, all information about books, authors, and sales is stored in one big table. This causes repeated data and makes it hard to update or find information.To fix this, you will learn how to split the data into smaller, related tables using normalization. This will reduce repetition and make the database easier to manage.
🎯 Goal: Create a simple database with three tables: Books, Authors, and Sales. Each table will store specific information to avoid repeating data. You will write SQL commands to create these tables and link them properly.
📋 What You'll Learn
Create a table called Authors with columns AuthorID (primary key) and Name.
Create a table called Books with columns BookID (primary key), Title, and AuthorID (foreign key).
Create a table called Sales with columns SaleID (primary key), BookID (foreign key), and Quantity.
Use proper SQL syntax to define primary keys and foreign keys.
Ensure the tables are normalized to avoid repeating author names or book titles in sales records.
💡 Why This Matters
🌍 Real World
Bookstores, libraries, and many businesses use normalized databases to keep their data clean and easy to update.
💼 Career
Database designers and developers must understand normalization to build efficient and reliable databases.
Progress0 / 4 steps
1
Create the Authors table
Write a SQL statement to create a table called Authors with two columns: AuthorID as an integer primary key, and Name as text.
SQL
Hint
Use CREATE TABLE Authors and define AuthorID as the primary key.
2
Create the Books table with foreign key
Write a SQL statement to create a table called Books with three columns: BookID as an integer primary key, Title as text, and AuthorID as an integer foreign key referencing Authors(AuthorID).
SQL
Hint
Remember to add a foreign key constraint on AuthorID that links to Authors.
3
Create the Sales table with foreign key
Write a SQL statement to create a table called Sales with three columns: SaleID as an integer primary key, BookID as an integer foreign key referencing Books(BookID), and Quantity as an integer.
SQL
Hint
Make sure to link BookID in Sales to the Books table.
4
Explain why normalization helps
Add a SQL comment at the end of your code explaining why splitting data into Authors, Books, and Sales tables helps avoid repeating data and makes the database easier to manage.
SQL
Hint
Write a comment starting with -- that explains how normalization reduces repeated data and improves management.
Practice
(1/5)
1. Why is normalization important in a database?
easy
A. It automatically creates backups of the database.
B. It makes the database run faster by using more memory.
C. It allows storing data in one big table without keys.
D. It reduces data duplication and improves data integrity.
Solution
Step 1: Understand what normalization does
Normalization organizes data to reduce repetition and avoid errors.
Step 2: Identify the main benefit
Reducing duplication helps keep data accurate and easier to update.
Final Answer:
It reduces data duplication and improves data integrity. -> Option D
Quick Check:
Normalization = less duplication [OK]
Hint: Normalization means less repeated data and fewer errors [OK]
Common Mistakes:
Thinking normalization speeds up all queries
Believing normalization stores everything in one table
Confusing normalization with backup processes
2. Which of the following is the correct way to represent a normalized table relationship?
easy
A. Separate tables for customers and orders linked by a customer ID.
B. One table with repeated customer addresses for each order.
C. All data combined in a single table without keys.
D. Storing all orders in a text file outside the database.
Solution
Step 1: Recall normalization structure
Normalization splits data into related tables connected by keys.
Step 2: Identify correct table design
Separate tables for customers and orders linked by customer ID avoid duplication.
Final Answer:
Separate tables for customers and orders linked by a customer ID. -> Option A
Quick Check:
Normalized tables use keys to link data [OK]
Hint: Normalized tables use keys to connect related data [OK]
Common Mistakes:
Repeating data in one big table
Ignoring foreign keys between tables
Storing data outside the database
3. Given two tables: Customers(customer_id, name, address) Orders(order_id, customer_id, product) What happens if you update a customer's address in the Customers table?
medium
A. The address updates in all related orders automatically.
B. The address in Orders table also changes because it stores addresses.
C. Only the address in the Customers table changes; orders remain linked by customer_id.
D. The database throws an error because address is duplicated.
Solution
Step 1: Understand table roles
Customers table stores addresses; Orders table links by customer_id only.
Step 2: Effect of updating address
Updating address changes it only in Customers; Orders remain linked by customer_id without address duplication.
Final Answer:
Only the address in the Customers table changes; orders remain linked by customer_id. -> Option C
Quick Check:
Normalized data updates in one place [OK]
Hint: Update data in one table; linked tables stay consistent [OK]
Common Mistakes:
Assuming address is stored in Orders table
Thinking all related tables update automatically
Believing address duplication causes errors
4. You have a table storing customer orders with repeated customer names and addresses. What is the main problem with this design?
medium
A. It improves query speed by avoiding joins.
B. It wastes space and risks inconsistent data.
C. It ensures data is always backed up.
D. It automatically normalizes data.
Solution
Step 1: Identify issue with repeated data
Repeating customer info wastes space and can cause inconsistent updates.
Step 2: Understand normalization benefit
Normalization avoids repetition, saving space and keeping data consistent.
Final Answer:
It wastes space and risks inconsistent data. -> Option B
Quick Check:
Repeated data = waste and errors [OK]
Hint: Repeated data wastes space and causes errors [OK]
Common Mistakes:
Thinking repeated data speeds up queries
Confusing normalization with backup
Believing database auto-fixes repetition
5. You have a table with columns: OrderID, CustomerName, CustomerAddress, Product. To normalize it, which step should you take?
hard
A. Split into two tables: Customers (CustomerID, CustomerName, CustomerAddress) and Orders (OrderID, Product, CustomerID).
B. Add more columns to store multiple addresses per customer.
C. Combine all data into one table without keys.
D. Store customer addresses as a comma-separated list in Orders.
Solution
Step 1: Identify repeated data
CustomerName and CustomerAddress repeat for each order, causing duplication.
Step 2: Apply normalization
Split data into Customers table (with unique customer info) and Orders table linked by CustomerID.
Final Answer:
Split into two tables: Customers (CustomerID, CustomerName, CustomerAddress) and Orders (OrderID, Product, CustomerID). -> Option A
Quick Check:
Normalization splits repeated data into related tables [OK]
Hint: Split repeated data into separate tables linked by keys [OK]
Common Mistakes:
Adding columns instead of splitting tables
Storing multiple addresses in one field
Ignoring keys to link tables
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.