DBMS Lab - 29 - SQL Dependencies

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Database Management System LAB # 29 Department of Technology

The University of Lahore

LAB No. 29

FUNCTIONAL DEPENDENCY
Functional Dependency
 A functional dependency is a constraint between two sets of attributes in a database
table.
 It specifies that the value of one attribute (or set of attributes) determines the value of
another attribute.
 It's denoted as X → Y, where X is the determinant and Y is the dependent.

Visualizing a Functional Dependency


Example

In a table of employees

Employee ID (X) → Employee Name (Y)

Knowing the Employee ID uniquely determines the Employee Name.

So, Employee Name will be dependent and Employee ID will be determinant.

Let’s Consider the following table and check the functional dependencies.

Table 1: Teacher Table

StudentI CourseID Instructor Grade


D
1 Math101 Dr. Smith A
2 Math101 Dr. Johnson B
3 Chem201 Dr. Davis C
4 Phys301 Dr. Brown A
5 Chem201 Dr. Davis B

InstructorCourseID: Yes, The Instructor uniquely determines the Course.

(StudentID, CourseID)Grade: Yes, the combination of Student and Course uniquely


determines the grade.

CourseIDInstructor: No, the CourseID cannot uniquely identify the Instructor.

GradeInstructor: No, the Grade cannot uniquely determine the Instructor.


Database Management System LAB # 29 Department of Technology
The University of Lahore
Fully Functional Dependency
Table 2:Student Record

StudentI CourseID Instructor EnrollmentDate Grade


D
1 Math101 Dr. Smith 2022-01-15 A
2 Math101 Dr. 2022-01-20 B
Johnson
3 Chem201 Dr. Davis 2022-02-01 C
4 Phys301 Dr. Brown 2022-02-10 A
5 Chem201 Dr. Davis 2022-02-15 B

(CourseID, Instructor)  Grade: Yes, Grade is fully functional dependent on CourseID


and Instructor.

Reason: If we remove the CourseID, Grade is not dependent on Instructor and if we remove
the Instructor, Grade is not dependent on CourseID but if both are present then dependency is
present and this dependency is called fully functional dependency.

Partially/Partial Functional Dependency


(StudentID, CourseID)  Grade: Yes, Grade is partially functional dependent on
StudentID and Instructor.

Reason: If we remove the CourseID, Grade is dependent on StudentID and if we remove the
StudentID, Grade is not dependent on CourseID, so, if dependency is present due any one of
the attribute then this dependency is called partial functional dependency.

Practice Questions
Table 3: Order Table

Order ID Customer ID Product ID Quantity Order Date Delivery Date


1001 XYZ123 ABC456 2 2023-12-19 2023-12-23
1001 XYZ123 DEF789 1 2023-12-19 2023-12-23
1002 PQR456 GHI101 3 2023-12-19 2023-12-26
1002 PQR456 JKL234 1 2023-12-19 2023-12-26
1003 MNO789 ABC456 1 2023-12-19 2023-12-28

Table 4: Library Table

Loan_ID Borrower_ID Book_ID Loan_Dat Due_Date Genre Author


e
Database Management System LAB # 29 Department of Technology
The University of Lahore
1 123 ABC 2023-12-20 2024-01-03 Fiction Jane Austen
1 123 DEF 2023-12-20 2024-01-03 Non-Fiction Y. Noah Harari
2 456 GHI 2023-12-20 2024-01-03 Fantasy J.R.R. Tolkien
2 456 JKL 2023-12-20 2024-01-03 Thriller John Grisham
3 789 MNO 2023-12-20 2024-01-03 Romance Colleen Hoover
3 789 PQR 2023-12-20 2024-01-03 Poetry Rupi Kaur

Question:

Identify all the possible Dependencies (Partially and fully


also) from the above tables.

You might also like