Download presentation
Presentation is loading. Please wait.
Published byTamsin Warner Modified over 8 years ago
1
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
2
3
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
4
SELECT EMP#, ENAME, JOB FROM EMP WHERE JOB = 'Programmer' 4 EMP#ENAMEJOB 1MaryProgrammer 2DuaneProgrammer 8NickProgrammer Functional dependencies include (EMP# ENAME) and (EMP# JOB) but not (EMP# SALARY)
5
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
6
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' 6 EMP#ENAMEJOBSTATUS 1MaryProgrammerFull time 2DuaneProgrammerFull time 5LarryAccountantPart time 8NickProgrammerFull time Functional dependencies include all applicable FDs from S plus (JOB STATUS) and (EMP# STATUS)
7
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
8
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
9
SELECT EMP#, ENAME AS ‘ENAME' FROM EMP WHERE JOB = 'Programmer' UNION SELECT EMP#, 'First Name: ' + ENAME AS ‘ENAME' FROM EMP WHERE JOB = 'Programmer' 9 EMP#ENAME 1Mary 1First Name: Mary 2Duane 2First Name: Duane 8Nick 8First Name: Nick The functional dependency (EMP# ENAME) does not survive the union.
10
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
11
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
12
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
13
If A B and C D then A U (C – B) BD 13
14
SELECT E.EMP#, E.ENAME, E.SALARY, D.LOCATION FROM EMP E, DEPT D WHERE E.DEPT# = D.DEPT# AND E.JOB = ‘Programmer’ 14 EMP#ENAMESALARYLOCATION 1Mary75000Alexandria 2Duane70000Alexandria 8Nick72000Alexandria
15
{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
16
16 Functional Dependencies include: EMP# SALARY EMP# ENAME EMP# LOCATION
17
17 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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.