Functional Dependency in DBMS Enggg.pptx

AyaanAliKhan4 13 views 23 slides Mar 02, 2025
Slide 1
Slide 1 of 23
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23

About This Presentation

DBMS Presentation


Slide Content

Functional Dependency in DBMS Understanding Concepts through Employee and Project Tables

Introduction to Functional Dependency A functional dependency (FD) in a database occurs when one attribute uniquely determines. The functional dependency is a relationship that exists between two attributes. It typically exists between the primary key and non-key attribute within a tables another. Importance in DBMS: Essential for normalization Ensures data integrity and minimizes redundancy Example - Emp_ID → Emp_Name (An employee ID determines the employee name)

Employee Table CREATE TABLE Employee ( Emp_ID VARCHAR2(10), Emp_Name VARCHAR2(50), Dept_ID VARCHAR2(10), Salary NUMBER ); INSERT INTO Employee VALUES ('E001', 'Alice Smith', 'D01', 70000); INSERT INTO Employee VALUES ('E002', 'Bob Johnson', 'D02', 65000); INSERT INTO Employee VALUES ('E003', 'Charlie Lee', 'D01', 72000);

Employee Table

Project Table CREATE TABLE Project ( Proj_ID VARCHAR2(10), Proj_Name VARCHAR2(50), Budget NUMBER ); INSERT INTO Project VALUES ('P101', 'Alpha Development', 500000); INSERT INTO Project VALUES ('P102', 'Beta Testing', 300000); INSERT INTO Project VALUES ('P103', 'Gamma Launch', 400000);

Project Table

Works_On Table CREATE TABLE Works_On ( Emp_ID VARCHAR2(10), Proj_ID VARCHAR2(10), Hours_Worked NUMBER ); INSERT INTO Works_On VALUES ('E001', 'P101', 35); INSERT INTO Works_On VALUES ('E002', 'P102', 40); INSERT INTO Works_On VALUES ('E003', 'P101', 30); INSERT INTO Works_On VALUES ('E001', 'P103', 20);

Works_On Table

Types of Functional Dependencies Trivial Functional Dependency Non-Trivial Functional Dependency Partial Functional Dependency Full Functional Dependency Transitive Functional Dependency

Types of Functional Dependencies 1. Trivial Functional Dependency - A dependency where an attribute is functionally dependent on itself or a subset of attributes. Example:Emp_ID , Proj_ID → Emp_ID Here, Emp_ID is trivially dependent on ( Emp_ID , Proj_ID ). SELECT Emp_ID , Emp_ID FROM Employee GROUP BY Emp_ID ;

Non-Trivial Functional Dependency When an attribute is functionally dependent on a combination of other attributes, and it’s not a trivial dependency. Example: Emp_ID → Dept Employee ID determines the department, which is non-trivial because Dept is not part of the primary key. SELECT Emp_ID , Emp_Name FROM Employee GROUP BY Emp_ID , Emp_Name ;

Partial Functional Dependency A non-prime attribute is functionally dependent on part of a candidate key. Example:( Emp_ID , Proj_ID ) → Emp_NameIn the Works On table, if Emp_ID is part of the composite key, but Emp_Name depends only on Emp_ID . SELECT Proj_ID , SUM( Hours_Worked ) FROM Works_On GROUP BY Proj_ID ;

Full Functional Dependency A non-prime attribute depends on the full composite key and not just a part of it. Example: ( Emp_ID , Proj_ID ) → Hours_Worked Hours worked by an employee depends on both the employee and the project. SELECT Emp_ID , Proj_ID , Hours_Worked FROM Works_On GROUP BY Emp_ID , Proj_ID , Hours_Worked ;

Transitive Functional Dependency When one attribute depends on another through a third attribute. Example: Emp_ID → Dept and Dept → Manager Therefore, Emp_ID → Manager (transitive dependency). CREATE TABLE Department ( Dept_ID VARCHAR2(10), Dept_Name VARCHAR2(50), Manager_ID VARCHAR2(10) ); INSERT INTO Department VALUES ('D01', 'Development', 'M001’); INSERT INTO Department VALUES ('D02', 'Testing', 'M002');

Transitive Functional Dependency -- Transitive Dependency Query SELECT E.Emp_ID , D.Manager_ID FROM Employee E JOIN Department D ON E.Dept_ID = D.Dept_ID ;

Inference Rules (Armstrong’s Axioms) Reflexivity Rule If Y is a subset of X, then X → Y. Example: Emp_ID → Emp_ID SELECT Emp_ID , Emp_Name FROM Employee GROUP BY Emp_ID , Emp_Name ;

Inference Rules (Armstrong’s Axioms) Augmentation Rule If X → Y, then XZ → YZ (adding additional attributes does not affect the dependency). Example: Emp_ID → Emp_Name implies ( Emp_ID , Proj_ID ) → ( Emp_Name , Proj_ID ) SELECT Emp_ID , Emp_Name , Proj_ID FROM Employee E JOIN Works_On W ON E.Emp_ID = W.Emp_ID ;

Inference Rules Transitivity Rule If X → Y and Y → Z, then X → Z. Example: Emp_ID → Dept and Dept → Manager implies Emp_ID → Manager SELECT E.Emp_ID , D.Manager_ID FROM Employee E JOIN Department D ON E.Dept_ID = D.Dept_ID ;

Inference Rules Decomposition Rule If X → YZ, then X → Y and X → Z. Example: ( Emp_ID , Proj_ID ) → ( Emp_Name , Hours_Worked ) implies Emp_ID → Emp_Name and ( Emp_ID , Proj_ID ) → Hours_Worked SELECT Emp_ID , Emp_Name , Salary FROM Employee GROUP BY Emp_ID , Emp_Name , Salary;

Inference Rules Union Rule If X → Y and X → Z, then X → YZ. Example: Emp_ID → Emp_Name and Emp_ID → Dept implies Emp_ID → ( Emp_Name , Dept) SELECT Emp_ID , Emp_Name , Salary FROM Employee GROUP BY Emp_ID , Emp_Name , Salary;

Inference Rules Pseudo-Transitivity Rule If X → Y and WY → Z, then WX → Z. Example: Emp_ID → Dept and ( Proj_ID , Dept) → Manager implies ( Emp_ID , Proj_ID ) → Manager SELECT W.Emp_ID , W.Proj_ID , P.Budget FROM Works_On W JOIN Project P ON W.Proj_ID = P.Proj_ID ;

Case Study - Normalizing Works_On Table Issue: Emp_Name repeats for the same Emp_ID . Solution: First Normal Form (1NF): Already satisfied (atomic values). Second Normal Form (2NF): Remove partial dependencies. Separate Emp_Name into Employee table.

THANK YOU
Tags