Functional Dependency Lesson Plan Using Flipped Classroom Approach
Functional Dependency Lesson Plan Using Flipped Classroom Approach
Classroom Approach
Overview
The flipped classroom approach involves students learning new content at home and
applying that knowledge during class time. For a lesson on functional dependencies, this
approach ensures that students grasp the theoretical aspects beforehand and engage in
problem-solving and discussions in class.
Objectives
Reading Material
A short online quiz to assess understanding of the video and reading materials.
Questions should cover definitions, identification, and examples of functional
dependencies.
Begin with a quick review of the key concepts from the video and reading.
Address any questions or confusion from the homework.
Post-Class Activities
Homework Assignment
Discussion Forum
Set up an online discussion forum for students to post questions and discuss the
homework assignment.
Encourage peer-to-peer interaction and support.
Follow-Up Quiz
Conduct an online quiz a week later to reinforce learning and assess retention.
Assessment
Formative Assessment
Summative Assessment
Resources
Definition: "A functional dependency occurs when one attribute uniquely determines
another attribute within a relational database. For example, if we have a table of student
records, the student ID uniquely determines the student's name, date of birth, and
address."
Example: "Consider a table with columns for student ID, student name, and student
address. The student ID is a primary key, meaning it uniquely identifies each student.
Therefore, we can say that the student name and address are functionally dependent on
the student ID."
Importance: "Functional dependencies are crucial for ensuring data integrity and
avoiding redundancy in databases. They help us normalize databases, which means
organizing the tables to reduce redundancy and improve efficiency."
Identification: "To identify functional dependencies, look for relationships where one
attribute or a combination of attributes determines another attribute. For example, in a
sales database, an order ID might determine the customer ID, product ID, and order
date."
Normalization: "Using functional dependencies, we can normalize a database by
dividing tables into smaller, related tables. This process helps eliminate redundancy and
ensures data integrity. For instance, if we have a table with order details, we might
normalize it by creating separate tables for customers, products, and orders."
Functional Dependencies:
Normalization:
Case Studies:
By using this flipped classroom approach, students actively engage with the content
before class and spend valuable class time applying their knowledge through
collaborative activities and discussions.
4o
Normalization examples?
ChatGPT
Normalization Examples
Problems:
In 1NF, we ensure that each column contains atomic (indivisible) values, and each entry
in a column is of the same type. The unnormalized table is already in 1NF.
To achieve 2NF, we need to separate the data into multiple tables. Here, OrderID and
ProductID together form the composite primary key.
1. Orders Table:
2. OrderDetails Table:
3. Products Table:
ProductID ProductName
P001 Widget A
P002 Widget B
In 3NF, we remove transitive dependencies; that is, no non-prime attribute should depend
on another non-prime attribute.
To achieve 3NF, we need to further decompose the tables if there are transitive
dependencies.
1. Customers Table:
2. Orders Table:
OrderID CustomerID
001 C001
OrderID CustomerID
002 C002
3. OrderDetails Table:
4. Products Table:
ProductID ProductName
P001 Widget A
P002 Widget B
1. UNF to 1NF:
o Ensure atomic values and consistent data types.
2. 1NF to 2NF:
o Remove partial dependencies by creating separate tables for entities (e.g.,
Orders, OrderDetails, Products).
3. 2NF to 3NF:
o Remove transitive dependencies by further decomposing tables to ensure
all non-prime attributes depend only on the primary key.
4o
More normalization steps?
ChatGPT
Beyond 3NF, databases can be further normalized to ensure even greater data integrity
and to handle more complex types of dependencies. These include Boyce-Codd Normal
Form (BCNF), Fourth Normal Form (4NF), and Fifth Normal Form (5NF).
BCNF is a stronger version of the 3NF. A table is in BCNF if it is in 3NF, and for every
one of its non-trivial functional dependencies X → Y, X is a super key.
Example:
Functional dependencies:
o (CourseID, Instructor) → Room
o Room → Instructor
The table is in 3NF but not in BCNF because Room is not a super key, yet it determines
Instructor. To convert it to BCNF, we split it:
1. CourseRoom Table:
CourseID Room
CS101 Room 1
CS102 Room 2
CS101 Room 3
2. RoomInstructor Table:
Room Instructor
Room 1 Dr. Smith
Room 2 Dr. Jones
Room 3 Dr. Smith
Example:
1. EmployeeProjects Table:
EmployeeID Project
E001 Project A
E001 Project B
2. EmployeeSkills Table:
EmployeeID Skill
E001 Skill X
E001 Skill Y
A table is in 5NF if it is in 4NF and cannot be decomposed into any number of smaller
tables without loss of data. It deals with cases where information can be reconstructed
from smaller pieces but not directly from the original table.
Example:
1. SupplierParts Table:
SupplierID PartID
S001 P001
S001 P002
S002 P001
2. SupplierProjects Table:
SupplierID ProjectID
S001 PR001
S002 PR002
3. PartProjects Table:
PartID ProjectID
P001 PR001
P002 PR001
P001 PR002
By following these additional steps, we ensure that the database design is robust, with
minimized redundancy and enhanced integrity even in complex s
To further understand BCNF, let's consider a few more examples where a table is in 3NF
but not in BCNF, and see how it can be decomposed into BCNF.
Functional Dependencies:
CourseID → Instructor
Instructor → Department
Problem:
The table is in 3NF because each non-key attribute (Instructor, Department) is
fully dependent on the primary key (CourseID), and there are no transitive
dependencies.
However, it is not in BCNF because Instructor determines Department, but
Instructor is not a super key.
1. Courses Table:
CourseID Instructor
CS101 Dr. Smith
CS102 Dr. Jones
MATH101 Dr. Brown
2. InstructorDepartment Table:
Instructor Department
Dr. Smith Computer Science
Dr. Jones Computer Science
Dr. Brown Mathematics
Functional Dependencies:
Problem:
EmployeeID ProjectID
E001 P001
E002 P002
E001 P002
2. ProjectManagers Table:
ProjectID ProjectManager
P001 M001
P002 M002
Functional Dependencies:
Problem:
The table is in 3NF because each non-key attribute (Instructor) is fully dependent
on the primary key (StudentID, CourseID), and there are no transitive
dependencies.
However, it is not in BCNF because CourseID determines Instructor, but
CourseID is not a super key.
1. StudentCourses Table:
StudentID CourseID
S001 CS101
S002 CS101
S003 MATH101
2. CourseInstructors Table:
CourseID Instructor
CS101 Dr. Smith
MATH101 Dr. Brown
Functional Dependencies:
Problem:
The table is in 3NF because each non-key attribute (Department) is fully
dependent on the primary key (EmployeeID, Skill), and there are no transitive
dependencies.
However, it is not in BCNF because Skill determines Department, but Skill is not
a super key.
1. EmployeeSkills Table:
EmployeeID Skill
E001 Java
E002 Python
E003 Excel
E001 Python
2. SkillDepartments Table:
Skill Department
Java IT
Python IT
Excel HR
Functional Dependencies:
Problem:
The table is in 3NF because each non-key attribute (Region) is fully dependent on
the primary key (SupplierID, ProductID), and there are no transitive
dependencies.
However, it is not in BCNF because ProductID determines Region, but ProductID
is not a super key.
Decomposition into BCNF:
1. SupplierProducts Table:
SupplierID ProductID
S001 P001
S001 P002
S002 P001
S002 P003
2. ProductRegions Table:
ProductID Region
P001 North
P002 North
P003 South
Functional Dependencies:
Problem:
1. StudentCourses Table:
StudentID CourseID
S001 C101
S002 C102
S001 C102
S003 C101
2. CourseInstructors Table:
CourseID InstructorID
C101 I001
C102 I002
Functional Dependencies:
Problem:
The table is in 3NF because each non-key attribute (Instructor) is fully dependent
on the primary key (RoomID, TimeSlot), and there are no transitive dependencies.
However, it is not in BCNF because TimeSlot determines Instructor, but TimeSlot
is not a super key.
1. RoomTimeSlots Table:
RoomID TimeSlot
R001 9-10AM
R002 10-11AM
R001 10-11AM
R002 11-12PM
2. TimeSlotInstructors Table:
TimeSlot Instructor
9-10AM Dr. Smith
10-11AM Dr. Jones
10-11AM Dr. Smith
11-12PM Dr. Brown
By analyzing these examples, you can see how to handle situations where tables are in
3NF but not in BCNF, and how to properly decompose them to achieve BCNF. This
ensures a robust database design that avoids redundancy and maintains data integrity.
Fourth Normal Form (4NF) deals with multi-valued dependencies, where a non-key
attribute depends on another non-key attribute independently of the primary key. A table
is in 4NF if it is in BCNF and contains no multi-valued dependencies.
Multi-Valued Dependencies:
EmployeeID →→ Skill
EmployeeID →→ Project
Problem:
Each employee can have multiple skills and be involved in multiple projects
independently.
1. EmployeeSkills Table:
EmployeeID Skill
E001 Java
E001 Python
E002 Python
2. EmployeeProjects Table:
EmployeeID Project
E001 Project A
E001 Project B
E002 Project B
Multi-Valued Dependencies:
StudentID →→ Course
StudentID →→ Activity
Problem:
Each student can enroll in multiple courses and participate in multiple activities
independently.
1. StudentCourses Table:
StudentID Course
S001 Math
S001 Science
S002 Science
2. StudentActivities Table:
StudentID Activity
S001 Chess Club
S001 Debate Team
S002 Debate Team
Multi-Valued Dependencies:
ProductID →→ Supplier
ProductID →→ Warehouse
Problem:
1. ProductSuppliers Table:
ProductID Supplier
P001 Supplier A
P001 Supplier B
P002 Supplier B
2. ProductWarehouses Table:
ProductID Warehouse
P001 Warehouse 1
P001 Warehouse 2
P002 Warehouse 2
Multi-Valued Dependencies:
AuthorID →→ BookTitle
AuthorID →→ Award
Problem:
Each author can write multiple books and win multiple awards independently.
1. AuthorBooks Table:
AuthorID BookTitle
A001 Book A
A001 Book B
A002 Book C
2. AuthorAwards Table:
AuthorID Award
A001 Award 1
A001 Award 2
A002 Award 2
Multi-Valued Dependencies:
CustomerID →→ Product
CustomerID →→ Preference
Problem:
Each customer can buy multiple products and have multiple preferences
independently.
1. CustomerProducts Table:
CustomerID Product
C001 Product A
C001 Product B
C002 Product B
2. CustomerPreferences Table:
CustomerID Preference
C001 Preference 1
C001 Preference 2
C002 Preference 2
4o
Fifth Normal Form (5NF), also known as Project-Join Normal Form (PJNF), addresses
issues where data redundancy arises due to join dependencies. A table is in 5NF if it is in
4NF and cannot be decomposed into any number of smaller tables without loss of data.
Example 1: Publisher-Author-Book
Join Dependencies:
Problem:
Each publisher can publish multiple books, and each book can have multiple
authors.
1. PublisherBooks Table:
PublisherID BookID
P001 B001
P002 B002
P002 B003
2. AuthorBooks Table:
AuthorID BookID
A001 B001
A002 B001
AuthorID BookID
A001 B002
A003 B003
3. PublisherAuthors Table:
PublisherID AuthorID
P001 A001
P001 A002
P002 A001
P002 A003
Example 2: Course-Teacher-Student
Join Dependencies:
Problem:
Each course can be taught by multiple teachers, and each teacher can have
multiple students.
1. CourseTeachers Table:
CourseID TeacherID
C001 T001
C001 T002
C002 T001
C002 T003
2. TeacherStudents Table:
TeacherID StudentID
T001 S001
T002 S001
T001 S002
T003 S003
3. CourseStudents Table:
CourseID StudentID
C001 S001
C002 S002
C002 S003
Example 3: Department-Project-Employee
Join Dependencies:
Problem:
Each department can handle multiple projects, and each project can have multiple
employees.
1. DepartmentProjects Table:
DepartmentID ProjectID
D001 P001
D001 P002
D002 P001
D002 P003
2. ProjectEmployees Table:
ProjectID EmployeeID
P001 E001
P002 E001
P001 E002
P003 E003
3. DepartmentEmployees Table:
DepartmentID EmployeeID
D001 E001
D002 E002
D002 E003
Example 4: Vendor-Product-Region
Join Dependencies:
Problem:
Each vendor can sell multiple products, and each product can be sold in multiple
regions.
1. VendorProducts Table:
VendorID ProductID
V001 P001
V001 P002
V002 P001
V002 P003
2. ProductRegions Table:
ProductID RegionID
P001 R001
P002 R001
P001 R002
P003 R002
3. VendorRegions Table:
VendorID RegionID
V001 R001
V002 R002
Example 5: Airline-Flight-Crew
Join Dependencies:
Problem:
Each airline can have multiple flights, and each flight can have multiple crew
members.
1. AirlineFlights Table:
AirlineID FlightID
A001 F001
A001 F002
A002 F001
A002 F003
2. FlightCrews Table:
FlightID CrewID
F001 C001
F002 C001
F001 C002
F003 C003
3. AirlineCrews Table:
AirlineID CrewID
A001 C001
A002 C002
A002 C003
By analyzing these additional examples, you can see how to handle join dependencies
and properly decompose tables to achieve 5NF, ensuring a highly normalized and
efficient database design.
Examples of Sixth Normal Form (6NF)
Sixth Normal Form (6NF) deals with temporal data and ensures that a table is
decomposed to the point where each constraint only involves one relationship between
key and non-key attributes. This form is relevant in temporal databases where the validity
of data is dependent on time. A table is in 6NF if it is in 5NF and all non-trivial join
dependencies are trivial.
Problem:
1. EmployeeContractStart Table:
2. EmployeeContractEnd Table:
Problem:
1. ProductPriceStart Table:
2. ProductPriceEnd Table:
Problem:
We need to track room booking schedules with start and end times.
2. RoomBookingEnd Table:
Problem:
1. EmployeeRoleStart Table:
2. EmployeeRoleEnd Table:
Problem:
1. ProductWarrantyStart Table:
2. ProductWarrantyEnd Table:
Temporal databases are used to manage data involving time aspects, such as valid time
and transaction time. These databases can track the history of data changes and handle
time-based queries. Here are some examples illustrating the use of temporal databases.
A temporal database can store the salary history of employees over time.
Schema:
1. Employee Table:
EmployeeID Name
E001 Alice
E002 Bob
Query Examples:
sql
Copy code
SELECT EmployeeID, Salary
FROM EmployeeSalary
WHERE EndDate = '9999-12-31';
sql
Copy code
SELECT Salary
FROM EmployeeSalary
WHERE EmployeeID = 'E001'
AND '2021-03-01' BETWEEN StartDate AND EndDate;
Schema:
1. Product Table:
ProductID ProductName
P001 Widget A
P002 Widget B
Query Examples:
sql
Copy code
SELECT ProductID, Price
FROM ProductPrice
WHERE EndDate = '9999-12-31';
sql
Copy code
SELECT Price
FROM ProductPrice
WHERE ProductID = 'P001'
AND '2020-05-01' BETWEEN StartDate AND EndDate;
Schema:
1. Room Table:
RoomID RoomName
R001 Conference Room 1
RoomID RoomName
R002 Conference Room 2
Query Examples:
sql
Copy code
SELECT RoomID, BookingID
FROM RoomBooking
WHERE EndDate > CURRENT_TIMESTAMP;
sql
Copy code
SELECT BookingID
FROM RoomBooking
WHERE RoomID = 'R001'
AND '2023-07-30' BETWEEN DATE(StartDate) AND DATE(EndDate);
A temporal database can track the membership history of customers over time.
Schema:
1. Customer Table:
CustomerID Name
C001 John Doe
C002 Jane Smith
Query Examples:
sql
Copy code
SELECT CustomerID, MembershipType
FROM Membership
WHERE EndDate = '9999-12-31';
sql
Copy code
SELECT MembershipType
FROM Membership
WHERE CustomerID = 'C001'
AND '2021-06-01' BETWEEN StartDate AND EndDate;
A temporal database can manage the availability history of products over time.
Schema:
1. Product Table:
ProductID ProductName
P001 Widget A
P002 Widget B
Query Examples:
sql
Copy code
SELECT Available
FROM ProductAvailability
WHERE ProductID = 'P001'
AND '2020-08-01' BETWEEN StartDate AND EndDate;
1. Valid Time:
o This tracks the period during which a fact is true in the real world. Tables
will have StartDate and EndDate columns.
2. Transaction Time:
o This tracks the period during which a fact is stored in the database. Tables
will have TransactionStart and TransactionEnd columns.
3. Temporal Queries:
o Use temporal operators and constructs in SQL (e.g., BETWEEN,
CURRENT_TIMESTAMP) to handle time-based queries effectively.
4. Normalization:
o Ensure that the temporal aspects are normalized properly to avoid
redundancy and maintain data integrity.
By using temporal tables and querying them appropriately, you can effectively manage
and analyze time-based data, providing valuable insights into historical trends and future
predictions.
Denormalization is the process of deliberately introducing redundancy into a database
schema by merging tables or adding duplicate data. This can be done to optimize
performance, especially in read-heavy environments. Here are the key benefits of
denormalization:
Benefits of Denormalization
Normalized Schema:
1. Orders Table:
2. Customers Table:
CustomerID CustomerName
C001 John Doe
C002 Jane Smith
3. OrderItems Table:
Denormalized Schema:
1. OrdersDenormalized Table:
Benefits Demonstrated:
Improved Query Performance: Queries to get all order details along with
customer names can be executed faster because all relevant data is in a single
table.
Simplified Queries: There’s no need to perform joins between orders, customers,
and order items tables. Queries are simpler and more straightforward.
Reduced Latency: Accessing data for reports or dashboards is faster since there
are fewer joins and aggregations required.
Trade-offs
While denormalization provides these benefits, it comes with trade-offs:
Normalization
Objectives:
Benefits:
1. Data Integrity:
o Ensures consistency and accuracy through well-defined relationships and
constraints.
2. Reduced Redundancy:
o Minimizes data duplication, which can save storage and reduce update
anomalies.
3. Flexibility:
o Makes it easier to update, insert, and delete records without affecting other
records.
Drawbacks:
1. Complex Queries:
o Often requires multiple joins to retrieve related data, which can complicate
queries and impact performance.
2. Performance Overhead:
o Joins and data retrieval operations can be slower due to the need for
complex query processing.
3. Higher Complexity:
o The schema can become complex with many tables and relationships,
making it harder to manage.
Denormalization
Objectives:
Improve Query Performance: Reduce the need for complex joins and
aggregations.
Simplify Query Design: Make queries simpler and more efficient by having all
necessary data in fewer tables.
Enhance Performance for Reporting: Optimize for systems where reporting
and analytics are crucial.
Benefits:
Drawbacks:
1. Increased Redundancy:
oData duplication can lead to increased storage requirements and potential
inconsistencies.
2. Update Anomalies:
o Changes need to be made in multiple places, increasing the risk of data
anomalies.
3. Complex Maintenance:
o Ensuring data consistency across denormalized tables can be more
challenging.
Data Warehousing: Where large amounts of data are aggregated for reporting
and analysis.
Read-heavy Systems: Applications where read operations are significantly more
frequent than write operations.
Performance Optimization: Systems that need to optimize for specific
performance metrics, such as query response time.
Comparison
Normalization: Best for transactional systems (OLTP) where data integrity and
minimizing redundancy are critical. It suits systems with frequent updates, inserts,
and deletes.
Denormalization: Best for analytical systems (OLAP) and reporting applications
where read performance is prioritized. It suits systems with complex queries or
reporting needs and high read-to-write ratios.
Both normalization and denormalization have their places in database design. The choice
between them depends on the specific requirements of the application, including
performance needs, data integrity requirements, and the nature of the operations
performed.