FDexamples

advertisement
Functional dependency: a relationship between two attributes (or
sub-sets of attributes) in a relational database, such that the value
of the first attribute determines the value of the second attribute in
the same tuple.
Examples:
SNAME is functionally dependent on S#.
(S#  SNAME)
SPJ.QTY is functionally dependent on S#, P# and J#.
(S#, P#, J#  QTY)
1
2
Let S and T be relations.
Let R be the the result of (S PROJECTION over set of
attributes P).
determinants of S  P INTERSECTION dependants of S
3
SELECT EMP#, ENAME, JOB
FROM EMP
WHERE JOB = 'Programmer'
EMP#
ENAME
JOB
1
Mary
Programmer
2
Duane
Programmer
8
Nick
Programmer
Functional dependencies include (EMP#  ENAME)
and (EMP#  JOB) but not (EMP#  SALARY)
4
Let S and T be relations.
Let R be the result of (S EXTEND BY attribute A).
All functional dependencies in S hold true in R.
Also, any attributes of A, which were input for the extension
operation will be determinants of A
5
SELECT EMP#, ENAME, JOB, CASE WHEN JOB = 'Programmer'
THEN 'Full time' ELSE 'Part time' END AS 'STATUS'
FROM EMP
WHERE JOB = 'Programmer' OR JOB = 'Accountant'
EMP#
ENAME
JOB
STATUS
1
Mary
Programmer
Full time
2
Duane
Programmer
Full time
5
Larry
Accountant
Part time
8
Nick
Programmer
Full time
Functional dependencies include all applicable FDs from S
plus (JOB  STATUS) and (EMP#  STATUS)
6
Let S and T be relations.
Let R be the result of (S RESTRICT BY condition C).
All functional dependencies in S hold true in R.
7
Let S and T be relations.
Let R be the relation resulting from the operation (S U T).
Functional dependencies in S and T will not hold true in R.
8
SELECT EMP#, ENAME AS ‘ENAME'
FROM EMP
WHERE JOB = 'Programmer'
UNION
SELECT EMP#, 'First Name: ' + ENAME AS
‘ENAME'
FROM EMP
WHERE JOB = 'Programmer'
EMP#
ENAME
1
Mary
1
First Name: Mary
2
Duane
2
First Name: Duane
8
Nick
8
First Name: Nick
The functional dependency
(EMP#  ENAME) does
not survive the union.
9
Let S and T be relations.
Let R be the result of operation (S INTERSECT T).
All functional dependencies in S and T hold true in R.
10
Let S and T be relations.
Let R be a relation resulting from the operation (S – T).
All functional dependencies that are true in S will also be true in R.
11
Let S and T be relations.
Let R be the result of the natural join of relations S and T on
attributes T.a = S.a
Kt is a candidate key for T and Ks is a candidate key for S.
C is the set of attributes that are common for T and S.
Ks U (Kt - C)  Header of R
Kt U (Ks - C)  Header of R
12
If A  B and C  D then A U (C – B)  BD
13
SELECT E.EMP#, E.ENAME, E.SALARY, D.LOCATION
FROM EMP E, DEPT D
WHERE E.DEPT# = D.DEPT#
AND E.JOB = ‘Programmer’
EMP#
ENAME
SALARY
LOCATION
1
Mary
75000
Alexandria
2
Duane
70000
Alexandria
8
Nick
72000
Alexandria
14
{EMP#} U ({DEPT#} – {EMP.DEPT#, DEPT.DEPT#})  HR
{EMP#}  HR
{DEPT#} U ({EMP#} – EMP.DEPT#, DEPT.DEPT#})  HR
{DEPT#, EMP#}  HR
HR = {ENAME, SALARY, LOCATION}
15
Functional Dependencies include:
EMP#  SALARY
EMP#  ENAME
EMP#  LOCATION
16
Functional dependencies are useful for improving performance, usability
and functionality in RDBMS.
Functional dependencies in derived tables can be determined from the the
functional dependencies in base tables.
Rules from this paper have been used to show that views that use a natural
join can be updated. Now included in SQL:1999.
17
Download