Organizing a Library Database in Third Normal Form (3NF)
📖 Scenario: You are helping a small library organize its book records. The library currently stores all information in one big table, which makes it hard to update and causes repeated data. You will break this big table into smaller, well-structured tables following the Third Normal Form (3NF) rules.
🎯 Goal: Create three separate tables: Books, Authors, and Publishers. Each table should have the right columns so that data is not repeated and each fact is stored only once. This will make the library database easier to maintain and update.
📋 What You'll Learn
Create a table called Books with columns BookID, Title, AuthorID, and PublisherID.
Create a table called Authors with columns AuthorID and AuthorName.
Create a table called Publishers with columns PublisherID and PublisherName.
Use AuthorID and PublisherID as foreign keys in the Books table to link to the other tables.
Ensure each table has a primary key to uniquely identify each record.
💡 Why This Matters
🌍 Real World
Libraries, bookstores, 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 initial Books table
Write a SQL statement to create a table called Books with columns BookID as an integer primary key, Title as text, AuthorID as integer, and PublisherID as integer.
SQL
Hint
Use CREATE TABLE Books and define each column with its type. Mark BookID as the primary key.
2
Create the Authors table
Write a SQL statement to create a table called Authors with columns AuthorID as an integer primary key and AuthorName as text.
SQL
Hint
Define Authors with AuthorID as primary key and AuthorName as text.
3
Create the Publishers table
Write a SQL statement to create a table called Publishers with columns PublisherID as an integer primary key and PublisherName as text.
SQL
Hint
Define Publishers with PublisherID as primary key and PublisherName as text.
4
Add foreign key constraints to Books table
Modify the Books table to add foreign key constraints on AuthorID referencing Authors(AuthorID) and on PublisherID referencing Publishers(PublisherID).
SQL
Hint
Use FOREIGN KEY clauses inside the Books table to link AuthorID and PublisherID to their tables.
Practice
(1/5)
1. Which of the following best describes Third Normal Form (3NF) in database design?
easy
A. Every non-key column depends only on the primary key.
B. Tables must have no more than three columns.
C. All columns must be unique across the table.
D. Data must be stored in a single table without duplicates.
Solution
Step 1: Understand 3NF definition
3NF requires that non-key columns depend only on the primary key, not on other non-key columns.
Step 2: Evaluate options
Every non-key column depends only on the primary key. correctly states this. The other options are incorrect descriptions of 3NF.
Final Answer:
Every non-key column depends only on the primary key. -> Option A
Quick Check:
3NF = Non-key columns depend only on primary key [OK]
Hint: 3NF means no column depends on non-key columns [OK]
Common Mistakes:
Confusing 3NF with limiting number of columns
Thinking all columns must be unique
Believing 3NF means one big table
2. Which SQL statement correctly creates a table that follows Third Normal Form (3NF)?
easy
A. CREATE TABLE Orders (OrderID INT PRIMARY KEY, CustomerID INT, CustomerName VARCHAR(50));
B. CREATE TABLE Orders (OrderID INT PRIMARY KEY, CustomerName VARCHAR(50), CustomerAddress VARCHAR(100));
C. CREATE TABLE Orders (OrderID INT PRIMARY KEY, CustomerID INT); CREATE TABLE Customers (CustomerID INT PRIMARY KEY, CustomerName VARCHAR(50));
D. CREATE TABLE Orders (OrderID INT, CustomerName VARCHAR(50));
Solution
Step 1: Identify 3NF compliance in table design
3NF requires separating data so non-key columns do not depend on other non-key columns. CustomerName depends on CustomerID, so it should be in a separate table.
Step 2: Analyze options
CREATE TABLE Orders (OrderID INT PRIMARY KEY, CustomerID INT); CREATE TABLE Customers (CustomerID INT PRIMARY KEY, CustomerName VARCHAR(50)); splits Orders and Customers, following 3NF. CREATE TABLE Orders (OrderID INT PRIMARY KEY, CustomerID INT, CustomerName VARCHAR(50)); stores CustomerName in Orders, violating 3NF. The other options miss primary keys or mix data improperly.
Final Answer:
CREATE TABLE Orders (OrderID INT PRIMARY KEY, CustomerID INT); CREATE TABLE Customers (CustomerID INT PRIMARY KEY, CustomerName VARCHAR(50)); -> Option C
Quick Check:
Separate related data into tables = 3NF [OK]
Hint: Split tables to avoid non-key dependencies [OK]
Common Mistakes:
Putting dependent data in the same table
Missing primary keys
Ignoring data duplication issues
3. Given the table below, which is NOT in Third Normal Form (3NF)?
EmployeeID | EmployeeName | Department | DepartmentHead
What is the main reason this table violates 3NF?
medium
A. DepartmentHead depends on Department, not EmployeeID.
B. EmployeeName depends on EmployeeID.
C. EmployeeID is not unique.
D. Department is a primary key.
Solution
Step 1: Identify dependencies in the table
DepartmentHead depends on Department, which is a non-key column, not on the primary key EmployeeID.
Step 2: Check 3NF rules
3NF requires no non-key column depends on another non-key column. Here, DepartmentHead depends on Department, violating 3NF.
Final Answer:
DepartmentHead depends on Department, not EmployeeID. -> Option A
Quick Check:
Non-key depends on non-key = violates 3NF [OK]
Hint: Check if non-key columns depend on other non-key columns [OK]
Common Mistakes:
Thinking EmployeeName dependency breaks 3NF
Assuming EmployeeID is not unique
Confusing primary key with foreign key
4. You have a table:
StudentID | StudentName | Advisor | AdvisorOffice
This table violates 3NF. What is the best way to fix it?
medium
A. Remove AdvisorOffice column.
B. Create a separate Advisor table with Advisor and AdvisorOffice.
C. Make StudentName the primary key.
D. Add AdvisorOffice to StudentID as a foreign key.
Solution
Step 1: Identify the 3NF violation
AdvisorOffice depends on Advisor, a non-key column, causing a transitive dependency violating 3NF.
Step 2: Fix by separating dependent data
Creating a separate Advisor table with Advisor and AdvisorOffice removes the transitive dependency.
Final Answer:
Create a separate Advisor table with Advisor and AdvisorOffice. -> Option B
Quick Check:
Separate dependent data into own table to fix 3NF [OK]
Hint: Fix 3NF by splitting tables for transitive dependencies [OK]