Functional dependence describes a relationship between attributes of a relation. If the attribute Y is functionally dependent on X (X
For example consider a relation with the attributes PostalCode, City, and Province. If PostalCode City, Province, then for all tuples in the relation, if they have equal PostalCode values, they must have the same City and Province.
The
Functional dependence can indicate to us that we're storing redundant data and can help us decompose relations without losing information.
Given a set of functional dependences for a relation we can derive additional functional dependences through the following methods:
The following axioms (known as Armstrong's Axioms) are sound and complete — they can derive all and only the functional dependencies that are logically implied by a given set. A set of axioms can be used to transform functional dependences
City, Major City).SID City, then SID, Major City, Major).SID City and City AreaCode, then SID AreaCode)These axioms can then be used to derive a few additional rules for ease of use
SID AreaCode and SID City, then SID AreaCode, City)SID AreaCode, City then SID AreaCode and SID City)Alternatively we can use the "closure method", given a set of attributes X we denote the closure of it as X
The algorithm is expressed as
Let Closure = X
Until Closure doesn't change do
if a
Consider the schema SupplierPart(supplierName, city, status, partNumber, partName, quantity) and the functional dependences
supplierName citycity statuspartNumber partNamesupplierName, partNumber quantityFind the closure of supplierName, partNumber, supplierName, and partNumber.
(supplierName, partNumber)supplierName, partNumber}
supplierName city is a functional dependence and {supplierName} is a subset of (supplierName, partNumber)city to (supplierName, partNumber)
(supplierName, partNumber)supplierName, partNumber, city}
city status is a functional dependence and {city} is a subset of (supplierName, partNumber)status to (supplierName, partNumber)
(supplierName, partNumber)supplierName, partNumber, city, status}
partNumber partName is a functional dependence and {partNumber} is a subset of (supplierName, partNumber)partName to (supplierName, partNumber)
(supplierName, partNumber)supplierName, partNumber, city, status, partName}
supplierName, partNumber quantity is a functional dependence and {supplierName, partNumber} is a subset of (supplierName, partNumber)quantity to (supplierName, partNumber)
(supplierName, partNumber)supplierName, partNumber, city, status, partName, quantity}
We've exhausted all function dependences so this is our final closure. This final closure contains all attributes of the schema so we know (supplierName, partNumber) is a super key.
supplierNamesupplierName}
supplierName city is a functional dependence and {supplierName} is a subset of supplierNamecity to supplierName
supplierNamesupplierName, city}
city status is a functional dependence and {city} is a subset of supplierNamestatus to supplierName
supplierNamesupplierName, city, status}
We've exhausted all functional dependencies which are contained in the closure so this is our final closure.
partNumberpartNumber}
partNumber partName is a functional dependence and {partNumber} is a subset of partNumberpartName to partNumber
partNumberpartNumber, partName}
We've exhausted all functional dependencies which are contained in the closure so this is our final closure.
Using those three closures we can see that supplierName, partNumber is a candidate key as reducing either supplierName or partNumber means the key is no longer a super key.