Click here to load reader

normalisation algorithms

  • View
    224

  • Download
    0

Embed Size (px)

Text of normalisation algorithms

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A BCNF Normalisation Algorithm

    Input:I A specification containing:

    1. a universal set of attributes U, and2. a set of functional dependencies (FDs) F over U.

    I An entity-relationship diagram (ERD) conforming tothe specification.

    Output: A database schema R which is in BCNF withrespect to F.

    Notes:I R = {R1,R2, . . . ,Rn}, where each Ri is a subset of U.I The union of all schema(Ri ) is U.I R is called a decomposition of U.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A BCNF Normalisation Algorithm

    Input:I A specification containing:

    1. a universal set of attributes U, and2. a set of functional dependencies (FDs) F over U.

    I An entity-relationship diagram (ERD) conforming tothe specification.

    Output: A database schema R which is in BCNF withrespect to F.

    Notes:I R = {R1,R2, . . . ,Rn}, where each Ri is a subset of U.I The union of all schema(Ri ) is U.I R is called a decomposition of U.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Strategy

    Step 1. Convert ERD into a database schema S.Step 2. If any of the relation schemas in S are not in

    BCNF with respect to F, then decomposethem further, using the DECOMPOSEalgorithm, given in this lecture.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Algorithm ERD-TO-BCNF(ERD, F)

    1. Convert ERD into a database schema S = {S1, . . . ,Sm};2. let the output database schema R be empty;3. for each Si in S do4. if TEST-BCNF(Si , F) = YES5. add Si to R;6. else7. merge DECOMPOSE(Si , F) and R;8. end for9. return the decomposition R;

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Testing whether a relation schema is in BCNF

    Algorithm TEST-BCNF(R, F)Assume F is a set of canonical FDs

    1. for each (non-trivial) X A in F+ do2. if X is not a superkey with respect to F3. return NO;4. end if5. end for6. return YES;

    Note that, in general, we need to consider F+, theclosure of F , to check whether there are any FDs whichviolate BCNF.

    But we can start trying to find violations in F , and onlyconsider F+ once we find no violations in F .

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Testing whether a relation schema is in BCNF

    Algorithm TEST-BCNF(R, F)Assume F is a set of canonical FDs

    1. for each (non-trivial) X A in F+ do2. if X is not a superkey with respect to F3. return NO;4. end if5. end for6. return YES;

    Note that, in general, we need to consider F+, theclosure of F , to check whether there are any FDs whichviolate BCNF.

    But we can start trying to find violations in F , and onlyconsider F+ once we find no violations in F .

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Example

    I Let schema(PHONE) = {cust-name, phone-num,phone-network}.

    I Let F = {cust-name phone-num, phone-num phone-network}.

    Is PHONE in BCNF with respect to F ?

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Decomposition Condition used by AlgorithmSo phone-num phone-network violates BCNF.

    I phone-num is the left-hand side of the violating FDI phone-network is the right-hand side of the violating

    FD

    Split PHONE into two relation schemas:

    1. R1 = NETWORK, with schema(NETWORK) ={phone-num, phone-network}, containing all theattributes in the violating FD, andF1 = { phone-num phone-network }.

    2. R2 = CUST, with schema(CUST) = {cust-name,phone-num}, containing the attributes inschema(PHONE) except those in the right-hand sideof the violating FD, andF2 = { cust-name phone-num }.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Decomposition Condition used by AlgorithmSo phone-num phone-network violates BCNF.

    I phone-num is the left-hand side of the violating FDI phone-network is the right-hand side of the violating

    FD

    Split PHONE into two relation schemas:

    1. R1 = NETWORK, with schema(NETWORK) ={phone-num, phone-network}, containing all theattributes in the violating FD, andF1 = { phone-num phone-network }.

    2. R2 = CUST, with schema(CUST) = {cust-name,phone-num}, containing the attributes inschema(PHONE) except those in the right-hand sideof the violating FD, andF2 = { cust-name phone-num }.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Decomposition Condition used by AlgorithmSo phone-num phone-network violates BCNF.

    I phone-num is the left-hand side of the violating FDI phone-network is the right-hand side of the violating

    FD

    Split PHONE into two relation schemas:

    1. R1 = NETWORK, with schema(NETWORK) ={phone-num, phone-network}, containing all theattributes in the violating FD, andF1 = { phone-num phone-network }.

    2. R2 = CUST, with schema(CUST) = {cust-name,phone-num}, containing the attributes inschema(PHONE) except those in the right-hand sideof the violating FD, andF2 = { cust-name phone-num }.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Algorithm DECOMPOSE(R, F )Assume F is a set of canonical FDs

    1. let the output database schema Out be empty;2. if TEST-BCNF(R, F) = YES then3. add R to Out;4. else5. let X A in F+ be nontrivial (i.e. A is not in X)

    such that X is not a superkey with respect to F;6. let R1 be a relation schema,

    with schema(R1) = X merged with A;7. merge DECOMPOSE(R1, F ) and Out;8. let R2 be a relation schema,

    with schema(R2) = schema(R) except A;9. merge DECOMPOSE(R2, F ) and Out;10. end if11. return Out;

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Result. DECOMPOSE(R, F) returns a decomposition ofschema(R).

    Result. The natural join can be applied to all of therelations in DECOMPOSE(R, F) to recover precisely theinformation stored in any relation over schema(R); this isknown as the lossless join property.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Lossless join

    Recall example: S is a relation schema, withschema(S) = {ENAME, CNAME, SAL} andsingle FD: ENAME SAL

    (Modified) relation s over S is given by

    ENAME CNAME SALJack Diane 25Jack John 25

    Donald Diane 30Donald David 30

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    If we decompose S into {ENAME,CNAME} and{CNAME,SAL} as follows:

    ENAME CNAMEJack DianeJack John

    Donald DianeDonald David

    CNAME SALDiane 25John 25Diane 30David 30

    and then perform the natural join, we get

    ENAME CNAME SALJack Diane 25Jack Diane 30Jack John 25

    Donald Diane 25Donald Diane 30Donald David 30

    with two tuples that were not in the original relation

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    If we decompose S into {ENAME,CNAME} and{CNAME,SAL} as follows:

    ENAME CNAMEJack DianeJack John

    Donald DianeDonald David

    CNAME SALDiane 25John 25Diane 30David 30

    and then perform the natural join, we get

    ENAME CNAME SALJack Diane 25Jack Diane 30Jack John 25

    Donald Diane 25Donald Diane 30Donald David 30

    with two tuples that were not in the original relation

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    I A decomposition such as that into {ENAME,CNAME}and {CNAME,SAL} is called lossy

    I We started knowing Jacks salary was 25I After decomposing, if we query Jacks salary we get

    both 25 and 30I The decomposition does not faithfully represent the

    original information we had

    I A decomposition which does faithfully represent theoriginal information is called lossless

    I The lossless condition is guaranteed if we ensurethat the common attributes between a pair ofdecomposed relation schemas is a key for one ofthem

    I The BCNF algorithm ensures losslessdecompositions

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    I A decomposition such as that into {ENAME,CNAME}and {CNAME,SAL} is called lossy

    I We started knowing Jacks salary was 25I After decomposing, if we query Jacks salary we get

    both 25 and 30I The decomposition does not faithfully represent the

    original information we hadI A decomposition which does faithfully represent the

    original information is called losslessI The lossless condition is guaranteed if we ensure

    that the common attributes between a pair ofdecomposed relation schemas is a key for one ofthem

    I The BCNF algorithm ensures losslessdecompositions

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Example of BCNF Decomposition

    Recall example involving employee names (ENAME),salaries (SAL) and children (CNAME). Lets call therelation schema EMP.

    The assumed set of FDs was F2 = { ENAME SAL }.I ENAME SAL violates BCNF in EMP, so

    decompose EMP intoES, with schema(ES) = { ENAME, SAL }, andEC, with schema(EC) = { ENAME, CNAME }

    I Both ES and EC are in BCNF:I ENAME is a key in ESI the only key for EC is (ENAME, CNAME)

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example of BCNF DecompositionLet STUD be a relation schema, with schema(STUD) ={SNUM, POSTCODE, CITY, COUNTRY}, with FDs{SNUM POSTCODE, POSTCODE CITY,CITY COUNTRY}

    I CITY COUNTRY violates BCNF in STUD, sodecompose STUD intoCC, with schema(CC) = {CITY, COUNTRY}, andSTUD1, with schema(STUD1) = {SNUM,POSTCODE, CITY}

    I CC is in BCNF while POSTCODE CITY violatesBCNF in STUD1, so decompose STUD1 intoPC, with schema(PC) = {POSTCODE, CITY}, andSINFO = {SNUM, POSTCODE}.

    I All the relation schemas in the database schema{CC, PC, SINFO} are now in BCNF

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example of BCNF DecompositionLet STUD be a relation schema, with schema(STUD) ={SNUM, POSTCODE, CITY, COUNTRY}, with FDs{SNUM POSTCODE, POSTCODE CITY,CITY COUNTRY}

    I CITY COUNTRY violates BCNF in STUD, sodecompose STUD intoCC, with schema(CC) = {CITY, COUNTRY}, andSTUD1, with schema(STUD1) = {SNUM,POSTCODE, CITY}

    I CC is in BCNF while POSTCODE CITY violatesBCNF in STUD1, so decompose STUD1 intoPC, with schema(PC) = {POSTCODE, CITY}, andSINFO = {SNUM, POSTCODE}.

    I All the relation schemas in the database schema{CC, PC, SINFO} are now in BCNF

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example of BCNF DecompositionLet STUD be a relation schema, with schema(STUD) ={SNUM, POSTCODE, CITY, COUNTRY}, with FDs{SNUM POSTCODE, POSTCODE CITY,CITY COUNTRY}

    I CITY COUNTRY violates BCNF in STUD, sodecompose STUD intoCC, with schema(CC) = {CITY, COUNTRY}, andSTUD1, with schema(STUD1) = {SNUM,POSTCODE, CITY}

    I CC is in BCNF while POSTCODE CITY violatesBCNF in STUD1, so decompose STUD1 intoPC, with schema(PC) = {POSTCODE, CITY}, andSINFO = {SNUM, POSTCODE}.

    I All the relation schemas in the database schema{CC, PC, SINFO} are now in BCNF

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example of BCNF DecompositionLet STUD be a relation schema, with schema(STUD) ={SNUM, POSTCODE, CITY, COUNTRY}, with FDs{SNUM POSTCODE, POSTCODE CITY,CITY COUNTRY}

    I CITY COUNTRY violates BCNF in STUD, sodecompose STUD intoCC, with schema(CC) = {CITY, COUNTRY}, andSTUD1, with schema(STUD1) = {SNUM,POSTCODE, CITY}

    I CC is in BCNF while POSTCODE CITY violatesBCNF in STUD1, so decompose STUD1 intoPC, with schema(PC) = {POSTCODE, CITY}, andSINFO = {SNUM, POSTCODE}.

    I All the relation schemas in the database schema{CC, PC, SINFO} are now in BCNF

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A Third Example

    I Consider a modified relation schema EMP, withattributes ENAME, CNAME (child name), DNAME(department name) and MNAME (manager name).

    I The set of FDs is F = {E D, D M, M D}, whereE stands for ENAME, D stands for DNAME and Mstands for MNAME (and C stands for child name).

    I All three FDs violate BCNF since EC is the only key.I We can choose any one of them as the basis for the

    first decomposition step.I We will consider all three decompositions in turn.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Third Example: Decomposition 1

    I If we first decompose using D M, we get twoschemas with attributes {D, M} and {E, C, D}.

    I FDs D M and M D are applicable to {D, M}, butboth D and M are keys.

    I FD E D is applicable to {E, C, D} and E is not asuperkey.

    I So we decompose {E, C, D} into {E, D} and {E, C}.I E is a key for {E, D} and EC is the key for {E, C}.I So the final database schema comprises

    {D, M}, {E, D} and {E, C}.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Third Example: Decomposition 2

    I If we first decompose using E D, we get twoschemas with attributes {E, D} and {E, C, M}.

    I E D is applicable to {E, D}, but E is a key.I What FDs are applicable to {E, C, M}?I None of E D, D M or M D apply because D is

    not in {E, C, M}.I We have to consider all FDs in F+.I Recall that E M follows from E D and D M.I E M violates BCNF in {E, C, M} because E is not a

    key.I So we decompose {E, C, M} into {E, M} and {E, C}.I So the final database schema comprises

    {E, D}, {E, M} and {E, C}.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Third Example: Decomposition 3

    I If we first decompose using M D, we get twoschemas with attributes {M, D} and {E, C, M}.

    I FDs D M and M D are applicable to {M, D}, butboth D and M are keys.

    I Once again we have {E, C, M}, so it is decomposedas before into {E, M} and {E, C}.

    I So the final database schema comprises{M, D}, {E, M} and {E, C}.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    An example for you to tryLet R be a relation schema, with schema(R) ={C,T,H,R,S,G}.

    I C stands for a course,I T stands for a teacher,I H stands for hour,I R stands for room,I S stands for student andI G stands for grade.

    An example set of FDs F over R :1. C T,2. HR C,3. HT R,4. CS G and5. HS R.

    Decompose R into BCNF.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Dependency Preservation

    Recall example: F3 = {SC P, P C}.S stands for Street, C stands for City and P stands forPostcode.

    {S,C,P} is not in BCNF

    Decompose {S,C,P} into {P,C} and {P,S}

    P Cp1 cp2 c

    P Sp1 sp2 s

    Only FD that can be tested in the decomposition is P C

    When we join the two relations, we see that SC P isviolated.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Dependency Preservation

    A decomposition is dependency preserving if the FDswhich hold on the original relation schema can be testedon the decomposed schemas, without using joins.

    We cannot always find a BCNF decomposition that isdependency preserving.

    To test that no FDs are violated, we may need to joinrelations (expensive).

    We can always find a 3NF dependency-preservingdecomposition.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Dependency Preservation

    For a starting set of attributes and FDs, some BCNFdecompositions may be dependency preserving andsome not.

    Consider the example with attributes { E, C, D, M } andFDs F = {E D, D M, M D}.

    We had three possible decompositions1. {D, M}, {E, D} and {E, C}.2. {E, D}, {E, M} and {E, C}.3. {M, D}, {E, M} and {E, C}.

    Which of them is dependency-preserving?

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    3NF Synthesis Algorithm

    Given a relation schema R and a set of FDs F, thefollowing steps produce a 3NF decomposition of R thatsatisfies the lossless join condition and is dependencypreserving:

    1. Find a minimal cover for F, say G.2. For each FD X A in G, use XA as the schema of

    one of the relations in the decomposition.3. If none of the schemas from Step 2 includes a

    superkey for R, add another relation schema that is akey for R.

    4. Delete any of the schemas from Step 2 that iscontained in another.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    3NF Synthesis Algorithm

    Given a relation schema R and a set of FDs F, thefollowing steps produce a 3NF decomposition of R thatsatisfies the lossless join condition and is dependencypreserving:

    1. Find a minimal cover for F, say G.

    2. For each FD X A in G, use XA as the schema ofone of the relations in the decomposition.

    3. If none of the schemas from Step 2 includes asuperkey for R, add another relation schema that is akey for R.

    4. Delete any of the schemas from Step 2 that iscontained in another.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    3NF Synthesis Algorithm

    Given a relation schema R and a set of FDs F, thefollowing steps produce a 3NF decomposition of R thatsatisfies the lossless join condition and is dependencypreserving:

    1. Find a minimal cover for F, say G.2. For each FD X A in G, use XA as the schema of

    one of the relations in the decomposition.

    3. If none of the schemas from Step 2 includes asuperkey for R, add another relation schema that is akey for R.

    4. Delete any of the schemas from Step 2 that iscontained in another.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    3NF Synthesis Algorithm

    Given a relation schema R and a set of FDs F, thefollowing steps produce a 3NF decomposition of R thatsatisfies the lossless join condition and is dependencypreserving:

    1. Find a minimal cover for F, say G.2. For each FD X A in G, use XA as the schema of

    one of the relations in the decomposition.3. If none of the schemas from Step 2 includes a

    superkey for R, add another relation schema that is akey for R.

    4. Delete any of the schemas from Step 2 that iscontained in another.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    3NF Synthesis Algorithm

    Given a relation schema R and a set of FDs F, thefollowing steps produce a 3NF decomposition of R thatsatisfies the lossless join condition and is dependencypreserving:

    1. Find a minimal cover for F, say G.2. For each FD X A in G, use XA as the schema of

    one of the relations in the decomposition.3. If none of the schemas from Step 2 includes a

    superkey for R, add another relation schema that is akey for R.

    4. Delete any of the schemas from Step 2 that iscontained in another.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Example of 3NF Synthesis

    Recall the example: F3 = {SC P, P C}.S stands for Street, C stands for City and P stands forPostcode.

    Step 1 of the algorithm finds that F3 is a minimal cover.

    Step 2 of the algorithm would produce {P,C} and {S,C,P}.

    Step 3 finds that SC is a superkey.

    Step 4 deletes {P,C} to leave just {S,C,P}.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Example of 3NF Synthesis

    Recall the example: F3 = {SC P, P C}.S stands for Street, C stands for City and P stands forPostcode.

    Step 1 of the algorithm finds that F3 is a minimal cover.

    Step 2 of the algorithm would produce {P,C} and {S,C,P}.

    Step 3 finds that SC is a superkey.

    Step 4 deletes {P,C} to leave just {S,C,P}.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Example of 3NF Synthesis

    Recall the example: F3 = {SC P, P C}.S stands for Street, C stands for City and P stands forPostcode.

    Step 1 of the algorithm finds that F3 is a minimal cover.

    Step 2 of the algorithm would produce {P,C} and {S,C,P}.

    Step 3 finds that SC is a superkey.

    Step 4 deletes {P,C} to leave just {S,C,P}.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Example of 3NF Synthesis

    Recall the example: F3 = {SC P, P C}.S stands for Street, C stands for City and P stands forPostcode.

    Step 1 of the algorithm finds that F3 is a minimal cover.

    Step 2 of the algorithm would produce {P,C} and {S,C,P}.

    Step 3 finds that SC is a superkey.

    Step 4 deletes {P,C} to leave just {S,C,P}.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Example of 3NF Synthesis

    Recall the example: F3 = {SC P, P C}.S stands for Street, C stands for City and P stands forPostcode.

    Step 1 of the algorithm finds that F3 is a minimal cover.

    Step 2 of the algorithm would produce {P,C} and {S,C,P}.

    Step 3 finds that SC is a superkey.

    Step 4 deletes {P,C} to leave just {S,C,P}.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example

    Recall the example: F2 = {E S}.E stands for ENAME, S stands for SAL and C stands forCNAME.

    Step 1 of the algorithm finds that F2 is a minimal cover.

    Step 2 of the algorithm would produce {E,S}.

    Step 3 finds no superkey, so adds relation schema {E,C}.

    Step 4 finds nothing to delete.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example

    Recall the example: F2 = {E S}.E stands for ENAME, S stands for SAL and C stands forCNAME.

    Step 1 of the algorithm finds that F2 is a minimal cover.

    Step 2 of the algorithm would produce {E,S}.

    Step 3 finds no superkey, so adds relation schema {E,C}.

    Step 4 finds nothing to delete.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example

    Recall the example: F2 = {E S}.E stands for ENAME, S stands for SAL and C stands forCNAME.

    Step 1 of the algorithm finds that F2 is a minimal cover.

    Step 2 of the algorithm would produce {E,S}.

    Step 3 finds no superkey, so adds relation schema {E,C}.

    Step 4 finds nothing to delete.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example

    Recall the example: F2 = {E S}.E stands for ENAME, S stands for SAL and C stands forCNAME.

    Step 1 of the algorithm finds that F2 is a minimal cover.

    Step 2 of the algorithm would produce {E,S}.

    Step 3 finds no superkey, so adds relation schema {E,C}.

    Step 4 finds nothing to delete.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    Another Example

    Recall the example: F2 = {E S}.E stands for ENAME, S stands for SAL and C stands forCNAME.

    Step 1 of the algorithm finds that F2 is a minimal cover.

    Step 2 of the algorithm would produce {E,S}.

    Step 3 finds no superkey, so adds relation schema {E,C}.

    Step 4 finds nothing to delete.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A Third Example

    Consider the example: F = {AB CD, C AD, D A }.

    Step 1 of the algorithm finds that F is not a minimal cover.

    First we form a canonical set of FDs:{AB C, AB D, C A, C D, D A }.

    Then we find that AB D and C A are redundant.

    So we are left with minimal coverG = {AB C, C D, D A }.

    The rest is easy.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A Third Example

    Consider the example: F = {AB CD, C AD, D A }.

    Step 1 of the algorithm finds that F is not a minimal cover.

    First we form a canonical set of FDs:{AB C, AB D, C A, C D, D A }.

    Then we find that AB D and C A are redundant.

    So we are left with minimal coverG = {AB C, C D, D A }.

    The rest is easy.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A Third Example

    Consider the example: F = {AB CD, C AD, D A }.

    Step 1 of the algorithm finds that F is not a minimal cover.

    First we form a canonical set of FDs:{AB C, AB D, C A, C D, D A }.

    Then we find that AB D and C A are redundant.

    So we are left with minimal coverG = {AB C, C D, D A }.

    The rest is easy.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A Third Example

    Consider the example: F = {AB CD, C AD, D A }.

    Step 1 of the algorithm finds that F is not a minimal cover.

    First we form a canonical set of FDs:{AB C, AB D, C A, C D, D A }.

    Then we find that AB D and C A are redundant.

    So we are left with minimal coverG = {AB C, C D, D A }.

    The rest is easy.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A Third Example

    Consider the example: F = {AB CD, C AD, D A }.

    Step 1 of the algorithm finds that F is not a minimal cover.

    First we form a canonical set of FDs:{AB C, AB D, C A, C D, D A }.

    Then we find that AB D and C A are redundant.

    So we are left with minimal coverG = {AB C, C D, D A }.

    The rest is easy.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    A Third Example

    Consider the example: F = {AB CD, C AD, D A }.

    Step 1 of the algorithm finds that F is not a minimal cover.

    First we form a canonical set of FDs:{AB C, AB D, C A, C D, D A }.

    Then we find that AB D and C A are redundant.

    So we are left with minimal coverG = {AB C, C D, D A }.

    The rest is easy.

  • DatabaseManagement

    Peter Wood

    NormalisationAlgorithmsBCNF Algorithm

    Lossless Join

    BCNF Examples

    Dependency Preservation

    3NF Algorithm

    An example for you to try

    Consider the set of attributes { Drinker, Address, Pub,Location, Beer, Cost }, along with the following set ofFDs:

    I Drinker AddressI Pub LocationI Pub, Beer Cost, Location

    Produce a set of 3NF relation schemas for the above.

    Normalisation AlgorithmsBCNF AlgorithmLossless JoinBCNF ExamplesDependency Preservation3NF Algorithm