
- DBMS - Home
- DBMS - Overview
- DBMS - Architecture
- DBMS - Data Models
- DBMS - Data Schemas
- DBMS - Data Independence
- DBMS - System Environment
- Centralized and Client/Server Architecture
- DBMS - Classification
- Relational Model
- DBMS - Codd's Rules
- DBMS - Relational Data Model
- DBMS - Relational Model Constraints
- DBMS - Relational Database Schemas
- DBMS - Handling Constraint Violations
- Entity Relationship Model
- DBMS - ER Model Basic Concepts
- DBMS - ER Diagram Representation
- Relationship Types and Relationship Sets
- DBMS - Weak Entity Types
- DBMS - Generalization, Aggregation
- DBMS - Drawing an ER Diagram
- DBMS - Enhanced ER Model
- Subclass, Superclass and Inheritance in EER
- Specialization and Generalization in Extended ER Model
- Data Abstraction and Knowledge Representation
- Relational Algebra
- DBMS - Relational Algebra
- Unary Relational Operation
- Set Theory Operations
- DBMS - Database Joins
- DBMS - Division Operation
- DBMS - ER to Relational Model
- Examples of Query in Relational Algebra
- Relational Calculus
- Tuple Relational Calculus
- Domain Relational Calculus
- Relational Database Design
- DBMS - Functional Dependency
- DBMS - Inference Rules
- DBMS - Minimal Cover
- Equivalence of Functional Dependency
- Finding Attribute Closure and Candidate Keys
- Relational Database Design
- DBMS - Keys
- Super keys and candidate keys
- DBMS - Foreign Key
- Finding Candidate Keys
- Normalization in Database Designing
- Database Normalization
- First Normal Form
- Second Normal Form
- Third Normal Form
- Boyce Codd Normal Form
- Difference Between 4NF and 5NF
- Structured Query Language
- Types of Languages in SQL
- Querying in SQL
- CRUD Operations in SQL
- Aggregation Function in SQL
- Join and Subquery in SQL
- Views in SQL
- Trigger and Schema Modification
- Storage and File Structure
- DBMS - Storage System
- DBMS - File Structure
- DBMS - Secondary Storage Devices
- DBMS - Buffer and Disk Blocks
- DBMS - Placing File Records on Disk
- DBMS - Ordered and Unordered Records
- Indexing and Hashing
- DBMS - Indexing
- DBMS - Single-Level Ordered Indexing
- DBMS - Multi-level Indexing
- Dynamic B- Tree and B+ Tree
- DBMS - Hashing
- Transaction and Concurrency
- DBMS - Transaction
- DBMS - Concurrency Control
- DBMS - Deadlock
- Backup and Recovery
- DBMS - Data Backup
- DBMS - Data Recovery
- DBMS Useful Resources
- DBMS - Quick Guide
- DBMS - Useful Resources
- DBMS - Discussion
Finding Attribute Closure and Candidate Keys using Functional Dependency
In database management and normalization, it's important that one understands the concepts of functional dependency, closure property, and candidate keys. These concepts help us design efficient relational schemas, ensure data integrity, and optimize queries. In this chapter, we will elaborate these concepts with the help of practical examples and also understand the process of finding closures and identifying candidate keys.
What is Functional Dependency?
For a basic recap on functional dependency, it describes a relationship between attributes in a relational schema. If X → Y, it means the value of X uniquely determines the value of Y. Now here, X is the determinant, and Y is the dependent.
Let us see one example for this. In a table where each employee has a unique ID, the dependency ID → Name this signifies that knowing an employee's ID is enough to find their name.
Functional dependencies can be defined formally. Consider two tuples, T1 and T2, in a relational schema. If T1.X = T2.X this implies T1.Y = T2.Y. Then X → Y is a valid functional dependency.
But this relationship is not necessarily reciprocal. So the attribute Y may not determine X.
Example of Functional Dependency
Let us consider a relational schema R (A, B, C) with the following data −
A | B | C |
---|---|---|
1 | 1 | 4 |
1 | 1 | 3 |
4 | 2 | 6 |
6 | 5 | 7 |
Let's understand the dependencies −
- A → C − This does not hold. This is because A = 1 maps to both C = 4 and C = 3.
- A → B − This is valid since each unique value of A maps to a unique value of B.
- B → A − This is also valid for the given dataset.
Thus, we derive the following functional dependencies −
- A → B
- B → A
What is Attribute Closure?
The closure of an attribute set, X, which is denoted as $\mathrm{X^{+}}$. This is the set of all attributes that can be determined by X using the given functional dependencies. The closures properties help us to identify keys and candidate keys for a relational schema.
Following are the Steps to Find Closure −
- We can start with $\mathrm{X^{+}}$ = X (the attribute set itself).
- Iteratively add attributes that can be determined from the functional dependencies.
- Stop when no more attributes can be added to $\mathrm{X^{+}}$.
Example of Closure
Using the functional dependencies, say, A → B, B → D, and CD → E −
Finding $\mathrm{A^{+}}$ | Finding $\mathrm{B^{+}}$ |
---|---|
|
|
Final closure: $\mathrm{A^{+} \:=\: \{A,\: B,\: C,\: D,\: E\}}$ | Final closure: $\mathrm{B^{+} \:=\:\{B,\: D\}}$ |
Concept of Candidate Key
A candidate key is a minimal set of attributes that can uniquely identify all other attributes in a relational schema.
- A candidate key's closure must contain all attributes in the schema.
- If multiple candidate keys exist, they provide alternate ways to uniquely identify tuples.
Finding Candidate Keys
To find candidate keys we must follow the following set of points in mind.
- Compute the closure of each attribute (or combination of attributes).
- If the closure contains all attributes in the schema then the attribute set is a candidate key.
- Ensure the minimality by checking if removing any attribute from the set still results in a closure containing all attributes.
Example of Candidate Keys
Relational Schema R (A, B, C, D, E) −
Functional dependencies −
- A → B, C
- B → D
- CD → E
Step 1: Find Closures
The following table highlights how you can find closures −
Finding $\mathrm{A^{+}}$ | $\mathrm{B^{+}}$ | $\mathrm{CD^{+}}$ |
---|---|---|
|
|
|
$\mathrm{A^{+}}$ contains all attributes, so A is a candidate key. | $\mathrm{B^{+}}$ does not contain all attributes, so B is not a candidate key. | CD is not a candidate key. |
Step 2: Check Combinations
Other candidate keys can be found by combining attributes and checking closures.
Shortcut for Finding Candidate Keys −
- If a single attribute or minimal set of attributes has a closure, and it is containing all schema attributes, that set is a candidate key. Additionally:
- If E is determined by CD, then CD can be replaced with CB. This combinations involving B should be checked.
By systematically using dependencies, we can infer keys without exhaustive searches.
Conclusion
In this chapter, we understood how to use functional dependencies to find closures and candidate keys. We started with the basics of functional dependency and understood its role in identifying relationships between attributes. Then, we used examples to understand how closures work and how they help determine candidate keys.
We also analyzed the efficient methods for finding candidate keys and highlighted their significance in relational schema design.