搜档网
当前位置:搜档网 › 数据库答案ch2ch3

数据库答案ch2ch3

数据库答案ch2ch3
数据库答案ch2ch3

Exercise 3.1.1

Answers for this exercise may vary because of different interpretations.

Some possible FDs:

Social Security number → name

Area code → state

Street address, city, state → zipcode

Possible keys:

{Social Security number, street address, city, state, area code, phone number}

Need street address, city, state to uniquely determine location. A person could have

multiple addresses. The same is true for phones. These days, a person could have a

landline and a cellular phone

Exercise 3.1.2

Answers for this exercise may vary because of different interpretations

Some possible FDs:

ID → x-position, y-position, z-position

ID → x-velocity, y-velocity, z-velocity

x-position, y-position, z-position → ID

Possible keys:

{ID}

{x-position, y-position, z-position}

The reason why the positions would be a key is no two molecules can occupy the same point. Exercise 3.1.3a

The superkeys are any subset that contains A1. Thus, there are 2(n-1) such subsets, since each of the n-1 attributes A2 through A n may independently be chosen in or out.

Exercise 3.1.3b

The superkeys are any subset that contains A1 or A2. There are 2(n-1) such subsets when considering A1 and the n-1 attributes A2 through A n. There are 2(n-2) such subsets when considering A2 and the n-2 attributes A3 through A n. We do not count A1 in these subsets because they are already counted in the first group of subsets. The total number of subsets is 2(n-1) + 2(n-2). Exercise 3.1.3c

The superkeys are any subset that contains {A1,A2} or {A3,A4}. There are 2(n-2) such subsets when considering {A1,A2} and the n-2 attributes A3 through A n. There are 2(n-2) – 2(n-4) such subsets when considering {A3,A4} and attributes A5 through A n along with the individual attributes A1 and A2. We get the 2(n-4) term because we have to discard the subsets that contain the key {A1,A2} to avoid double counting. The total number of subsets is 2(n-2) + 2(n-2) – 2(n-4).

Exercise 3.1.3d

The superkeys are any subset that contains {A1,A2} or {A1,A3}. There are 2(n-2) such subsets when considering {A1,A2} and the n-2 attributes A3 through A n. There are 2(n-3) such subsets when considering {A1,A3} and the n-3 attributes A4 through A n We do not count A2 in these subsets because they are already counted in the first group of subsets. The total number of subsets is 2(n-2) + 2(n-3).

Exercise 3.2.1a

We could try inference rules to deduce new dependencies until we are satisfied we have them all.

A more systematic way is to consider the closures of all 15 nonempty sets of attributes.

For the single attributes we have {A}+ = A, {B}+ = B, {C}+ = ACD, and {D}+ = AD. Thus, the only new dependency we get with a single attribute on the left is C→A.

Now consider pairs of attributes:

{AB}+ = ABCD, so we get new dependency AB→D. {AC}+ = ACD, and AC→D is nontrivial. {AD}+ = AD, so nothing new. {BC}+ = ABCD, so we get BC→A, and BC→D. {BD}+ = ABCD, giving us BD→A and BD→C. {CD}+ = ACD, giving CD→A.

For the triples of attributes, {ACD}+ = ACD, but the closures of the other sets are each ABCD. Thus, we get new dependencies ABC→D, ABD→C, and BCD→A.

Since {ABCD}+ = ABCD, we get no new dependencies.

The collection of 11 new dependencies mentioned above are:

C→A, AB→D, AC→D, BC→A, BC→D, BD→A, BD→C, CD→A, ABC→D, ABD→C, and BCD→A.

Exercise 3.2.1b

From the analysis of closures above, we find that AB, BC, and BD are keys. All other sets either do not have ABCD as the closure or contain one of these three sets.

Exercise 3.2.1c

The superkeys are all those that contain one of those three keys. That is, a superkey that is not a key must contain B and more than one of A, C, and D. Thus, the (proper) superkeys are ABC, ABD, BCD, and ABCD.

Exercise 3.2.2a

i) For the single attributes we have {A}+ = ABCD, {B}+ = BCD, {C}+ = C, and {D}+ = D. Thus, the new dependencies are A→C and A→D.

Now consider pairs of attributes:

{AB}+ = ABCD, {AC}+ = ABCD, {AD}+ = ABCD, {BC}+ = BCD, {BD}+ = BCD, {CD}+ = CD. Thus the new dependencies are AB→C, AB→D, AC→B, AC→D, AD→B, AD→C,

BC→D and BD→C.

For the triples of attributes, {BCD}+ = BCD, but the closures of the other sets are each ABCD. Thus, we get new dependencies ABC→D, ABD→C, and ACD→B.

Since {ABCD}+ = ABCD, we get no new dependencies.

The collection of 13 new dependencies mentioned above are:

A→C, A→D, AB→C, AB→D, AC→B, AC→D, AD→B, AD→C, BC→D, BD→C, ABC→D, ABD→C and ACD→B.

ii) For the single attributes we have {A}+ = A, {B}+ = B, {C}+ = C, and {D}+ = D. Thus, there are no new dependencies.

Now consider pairs of attributes:

{AB}+ = ABCD, {AC}+ = AC, {AD}+ = ABCD, {BC}+ = ABCD, {BD}+ = BD, {CD}+ = ABCD. Thus the new dependencies are AB→D, AD→C, BC→A and CD→B.

For the triples of attributes, all the closures of the sets are each ABCD. Thus, we get new dependencies ABC→D, ABD→C, ACD→B and BCD→A.

Since {ABCD}+ = ABCD, we get no new dependencies.

The collection of 8 new dependencies mentioned above are:

AB→D, AD→C, BC→A, CD→B, ABC→D, ABD→C, ACD→B and BCD→A.

iii) For the single attributes we have {A}+ = ABCD, {B}+ = ABCD, {C}+ = ABCD, and {D}+ = ABCD. Thus, the new dependencies are A→C, A→D, B→D, B→A, C→A, C→B, D→B and

D→C.

Since all the single attributes’ closures are ABCD, any superset of the single attributes will also lead to a closure of ABCD. Knowing this, we can enumerate the rest of the new dependencies. The collection of 24 new dependencies mentioned above are:

A→C, A→D, B→D, B→A, C→A, C→B, D→B, D→C, AB→C, AB→D, AC→B, AC→D, AD→B, AD→C, BC→A, BC→D, BD→A, BD→C, CD→A, CD→B, ABC→D, ABD→C, ACD→B and BCD→A.

Exercise 3.2.2b

i) From the analysis of closures in 3.2.2a(i), we find that the only key is A. All other sets either do not have ABCD as the closure or contain A.

ii) From the analysis of closures 3.2.2a(ii), we find that AB, AD, BC, and CD are keys. All other sets either do not have ABCD as the closure or contain one of these four sets.

iii) From the analysis of closures 3.2.2a(iii), we find that A, B, C and D are keys. All other sets either do not have ABCD as the closure or contain one of these four sets.

Exercise 3.2.2c

i) The superkeys are all those sets that contain one of the keys in 3.2.2b(i). The superkeys are AB, AC, AD, ABC, ABD, ACD, BCD and ABCD.

ii) The superkeys are all those sets that contain one of the keys in 3.2.2b(ii). The superkeys are ABC, ABD, ACD, BCD and ABCD.

iii) The superkeys are all those sets that contain one of the keys in 3.2.2b(iii). The superkeys are AB, AC, AD, BC, BD, CD, ABC, ABD, ACD, BCD and ABCD.

Exercise 3.2.3a

Since A1A2…A n C contains A1A2…A n, then the closure of A1A2…A n C contains B. Thus it follows that A1A2…A n C→B.

Exercise 3.2.3b

From 3.2.3a, we know that A1A2…A n C→B. Using the concept of trivial dependencies, we can show that A1A2…A n C→C. Thus A1A2…A n C→BC.

Exercise 3.2.3c

From A1A2…A n E1E2…E j, we know that the closure contains B1B2…B m because of the FD

A1A2…A n→ B1B2…B m. The B1B2…B m and the E1E2…E j combine to form the C1C2…C k. Thus the closure of A1A2…A n E1E2…E j contains D as well. Thus, A1A2…A n E1E2…E j→D.

Exercise 3.2.3d

From A1A2…A n C1C2…C k, we know that the closure contains B1B2…B m because of the FD

A1A2…A n→ B1B2…B m. The C1C2…C k also tell us that the closure of A1A2…A n C1C2…C k contains D1D2…D j. Thus, A1A2…A n C1C2…C k→B1B2…B k D1D2…D j.

Exercise 3.2.4a

If attribute A represented Social Security Number and B represented a person’s name, then we would assume A→B but B→A would not be valid because there may be many people with the same name and different Social Security Numbers.

Exercise 3.2.4b

Let attribute A represent Social Security Number, B represent gender and C represent name. Surely Social Security Nu mber and gender can uniquely identify a person’s name (i.e. AB→C).

A Social Security Number can also uniquely identify a person’s name (i.e. A→C). However, gender does not uniquely determine a name (i.e. B→C is not valid).

Exercise 3.2.4c

Let attribute A represent latitude and B represent longitude. Together, both attributes can uniquely determine C, a point on the world map (i.e. AB→C). However, neither A nor B can uniquely identify a point (i.e. A→C and B→C are not valid).

Exercise 3.2.5

Given a relation with attributes A1A2…A n, we are told that there are no functional dependencies of the form B1B2…B n-1→C where B1B2…B n-1 is n-1 of the attributes from A1A2…A n and C is the remaining attribute from A1A2…A n. In this case, the set B1B2…B n-1 and any subset do not functionally determine C. Thus the only functional dependencies that we can make are ones where C is on both the left and right hand sides. All of these functional dependencies would be trivial and thus the relation has no nontrivial FD’s.

Exercise 3.2.6

Let’s prove this by using the contrapositive. We wish to show that if X+ is not a subset of Y+, then it must be that X is not a subset of Y.

If X+ is not a subset of Y+, there must be attributes A1A2…A n in X+ that are not in Y+. If any of these attributes were originally in X, then we are done because Y does not contain any of the

A1A2…A n. However, if the A1A2…A n were added by the closure, then we must examine the case further. Assume that there was some FD C1C2…C m→A1A2…A j where A1A2…A j is some subset of A1A2…A n. It must be then that C1C2…C m or some subset of C1C2…C m is in X. However, the attributes C1C2…C m cannot be in Y because we assumed that attributes A1A2…A n are only in X+ and are not in Y+. Thus, X is not a subset of Y.

By proving the contrapositive, we have also proved if X? Y, then X+? Y+.

Exercise 3.2.7

The algorithm to find X+ is outlined on pg. 76. Using that algorithm, we can prove that

(X+)+ = X+. We will do this by using a proof by contradiction.

Suppose that (X+)+≠ X+. Then for (X+)+, it must be that some FD allowed additional attributes to be added to the original set X+. For example, X+→ A where A is some attribute not in X+. However, if this were the case, then X+ would not be the closure of X. The closure of X would have to include A as well. This contradicts the fact that we were given the closure of X, X+. Therefore, it must be that (X+)+ = X+ or else X+ is not the closure of X.

Exercise 3.2.8a

If all sets of attributes are closed, then there cannot be any nontrivial functional dependencies. Suppose A1A2...A n→B is a nontrivial dependency. Then {A1A2...A n}+ contains B and thus

A1A2...A n is not closed.

Exercise 3.2.8b

If the only closed sets are ? and {A,B,C,D}, then the following FDs hold:

A→B A→C A→D

B→A B→C B→D

C→A C→B C→D

D→A D→B D→C

AB→C AB→D

AC→B AC→D

AD→B AD→C

BC→A BC→D

BD→A BD→C

CD→A CD→B

ABC→D

ABD→C

ACD→B

BCD→A

Exercise 3.2.8c

If the only closed sets are ?, {A,B} and {A,B,C,D}, then the following FDs hold:

A→B

B→A

C→A C→B C→D

D→A D→B D→C

AC→B AC→D

AD→B AD→C

BC→A BC→D

BD→A BD→C

CD→A CD→B

ABC→D

ABD→C

ACD→B

BCD→A

Exercise 3.2.9

We can think of this problem as a situation where the attributes A,B,C represent cities and the functional dependencies represent one way paths between the cities. The minimal bases are the minimal number of pathways that are needed to connect the cities. We do not want to create another roadway if the two cities are already connected.

The systematic way to do this would be to check all possible sets of the pathways. However, we can simplify the situation by noting that it takes more than two pathways to visit the two other cities and come back. Also, if we find a set of pathways that is minimal, adding additional pathways will not create another minimal set.

The two sets of minimal bases that were given in example 3.11 are:

{A→B, B→C, C→A}

{A→B, B→A, B→C, C→B}

The additional sets of minimal bases are:

{C→B, B→A, A→C}

{A→B, A→C, B→A, C→A}

{A→C, B→C, C→A, C→B}

Exercise 3.2.10a

We need to compute the closures of all subsets of {ABC}, although there is no need to think about the empty set or the set of all three attributes. Here are the calculations for the remaining six sets:

{A}+=A

{B}+=B

{C}+=ACE

{AB}+=ABCDE

{AC}+=ACE

{BC}+=ABCDE

We ignore D and E, so a basis for the resulting functional dependencies for ABC is: C→A and AB→C. Note that BC->A is true, but follows logically from C->A, and therefore may be omitted from our list.

Exercise 3.2.10b

We need to compute the closures of all subsets of {ABC}, although there is no need to think about the empty set or the set of all three attributes. Here are the calculations for the remaining six sets:

{A}+=AD

{B}+=B

{C}+=C

{AB}+=ABDE

{AC}+=ABCDE

{BC}+=BC

We ignore D and E, so a basis for the resulting functional dependencies for ABC is: AC→B. Exercise 3.2.10c

We need to compute the closures of all subsets of {ABC}, although there is no need to think about the empty set or the set of all three attributes. Here are the calculations for the remaining six sets:

{A}+=A

{B}+=B

{C}+=C

{AB}+=ABD

{AC}+=ABCDE

{BC}+=ABCDE

We ignore D and E, so a basis for the resulting functional dependencies for ABC is: AC→B and BC→A.

Exercise 3.2.10d

We need to compute the closures of all subsets of {ABC}, although there is no need to think about the empty set or the set of all three attributes. Here are the calculations for the remaining six sets:

{A}+=ABCDE

{B}+=ABCDE

{C}+=ABCDE

{AB}+=ABCDE

{AC}+=ABCDE

{BC}+=ABCDE

We ignore D and E, so a basis for the resulting functional dependencies for ABC is: A→B, B→C and C→A.

Exercise 3.2.11

For step one of Algorithm 3.7, suppose we have the FD ABC→DE. We want to use Armstrong’s Axioms to show that ABC→D and ABC→E follow. Surely the functional dependencies DE→D

and DE→E hold because they are trivial and follow the reflexivity property. Using the transitivity rule, we can derive the FD ABC→D from the FDs ABC→DE and DE→D. Likewise, we can do the same for ABC→DE and DE→E and derive the FD ABC→E.

For steps two through four of Algorithm 3.7, suppose we have the initial set of attributes of the closure as ABC. Suppose also that we have FDs C→D and D→E. According to Algorithm 3.7, the closure should become ABCDE. Taking the FD C→D and augmenting both sides with attributes AB we get the FD ABC→ABD. We can use the splitting method in step one to get the FD ABC→D. Since D is not in the closure, we can add attribute D. Taking the FD D→E and augmenting both sides with attributes ABC we get the FD ABCD→ABCDE. Using again the splitting method in step one we get the FD ABCD→E. Since E is not in the closure, we can add attribute E.

Given a set of FDs, we can prove that a FD F follows by taking the closure of the left side of FD F. The steps to compute the closure in Algorithm 3.7 can be mimicked by Armstrong’s axioms and thus we can prove F from the given set of FD s using Armstrong’s axioms.

Exercise 3.3.1a

In the solution to Exercise 3.2.1 we found that there are 14 nontrivial dependencies, including the three given ones and eleven derived dependencies. They are: C→A, C→D, D→A, AB→D,

AB→ C, AC→D, BC→A, BC→D, BD→A, BD→C, CD→A, ABC→D, ABD→C, and

BCD→A.

We also learned that the three keys were AB, BC, and BD. Thus, any dependency above that does not have one of these pairs on the left is a BCNF violation. These are: C→A, C→D, D→A, AC→D, and CD→A.

One choice is to decompose using the violation C→D. Using the above FDs, we get ACD and BC as decomposed relations. BC is surely in BCNF, since any two-attribute relation is. Using Algorithm 3.12 to discover the projection of FDs on relation ACD, we discover that ACD is not in BCNF since C is its only key. However, D→A is a dependency that holds in ABCD and therefore holds in ACD. We must further decompose ACD into AD and CD. Thus, the three relations of the decomposition are BC, AD, and CD.

Exercise 3.3.1b

By computing the closures of all 15 nonempty subsets of ABCD, we can find all the nontrivial FDs. They are B→C, B→D, AB→C, AB→D, BC→D, BD→C, ABC→D and ABD→C. From the closures we can also deduce that the only key is AB. Thus, any dependency above that does not contain AB on the left is a BCNF violation. These are: B→C, B→D, BC→D and BD→C. One choice is to decompose using the violation B→C. Using the above FDs, we get BCD and AB as decomposed relations. AB is surely in BCNF, since any two-attribute relation is. Using Algorithm 3.12 to discover the projection of FDs on relation BCD, we discover that BCD is in

BCNF since B is its only key and the projected FDs all have B on the left side. Thus the two relations of the decomposition are AB and BCD.

Exercise 3.3.1c

In the solution to Exercise 3.2.2(ii), we found that there are 12 nontrivial dependencies, including the four given ones and the eight derived ones. They are AB→C, BC→D, CD→A, AD→B,

AB→D, AD→C, BC→A, CD→B, ABC→D, ABD→C, ACD→B and BCD→A.

We also found out that the keys are AB, AD, BC, and CD. Thus, any dependency above that does not have one of these pairs on the left is a BCNF violation. However, all of the FDs contain a key on the left so there are no BCNF violations.

No decomposition is necessary since all the FDs do not violate BCNF.

Exercise 3.3.1d

In the solution to Exercise 3.2.2(iii), we found that there are 28 nontrivial dependencies, including the four given ones and the 24 derived ones. They are A→B, B→C, C→D, D→A,

A→C, A→D, B→D, B→A, C→A, C→B, D→B, D→C, AB→C, AB→D, AC→B, AC→D,

AD→B, AD→C, BC→A, BC→D, BD→A, BD→C, CD→A, CD→B, ABC→D, ABD→C, ACD→B and BCD→A.

We also found out that the keys are A,B,C,D. Thus, any dependency above that does not have one of these attributes on the left is a BCNF violation. However, all of the FDs contain a key on the left so there are no BCNF violations.

No decomposition is necessary since all the FDs do not violate BCNF.

Exercise 3.3.1e

By computing the closures of all 31 nonempty subsets of ABCDE, we can find all the nontrivial FDs. They are AB→C, DE→C, B→D, AB→D, BC→D, BE→C, BE→D, ABC→D, ABD→C, ABE→C, ABE→D, ADE→C, BCE→D, BDE→C, ABCE→D, and ABDE→C. From the closures we can also deduce that the only key is ABE. Thus, any dependency above that does not contain ABE on the left is a BCNF violation. These are: AB→C, DE→C, B→D, AB→D,

BC→D, BE→C, BE→D, ABC→D, ABD→C, ADE→C, BCE→D and BDE→C.

One choice is to decompose using the violation AB→C. Using the above FDs, we get ABCD and ABE as decomposed relations. Using Algorithm 3.12 to discover the projection of FDs on relation ABCD, we discover that ABCD is not in BCNF since AB is its only key and the FD

B→D follows for ABCD. Using violation B→D to further decompose, we get BD and ABC as decomposed relations. BD is in BCNF because it is a two-attribute relation. Using Algorithm

3.12 again, we discover that ABC is in BCNF since AB is the only key and AB→C is the only nontrivial FD. Going back to relation ABE, following Algorithm 3.12 tells us that ABE is in

BCNF because there are no keys and no nontrivial FDs. Thus the three relations of the decomposition are ABC, BD and ABE.

Exercise 3.3.1f

By computing the closures of all 31 nonempty subsets of ABCDE, we can find all the nontrivial FDs. They are: C→B, C→D, C→E, D→B, D→E, AB→C, AB→D, AB→E, AC→B, AC→D, AC→E, AD→B, AD→C, AD→E, BC→D, BC→E, BD→E, CD→B, CD→E, CE→B, CE→D, DE→B, ABC→D, ABC→E, ABD→C, ABD→E, ABE→C, ABE→D, ACD→B, ACD→E, ACE→B, ACE→D, ADE→B, ADE→C, BCD→E, BCE→D, CDE→B, ABCD→E, ABCE→D, ABDE→C and ACDE→B. From the closures we can also deduce that the keys are AB, AC and AD. Thus, any dependency above that does not contain one of the above pairs on the left is a BCNF violation. These are: C→B, C→D, C→E, D→B, D→E, BC→D, BC→E, BD→E, CD→B, CD→E, CE→B, CE→D, DE→B, BCD→E, BCE→D and CDE→B.

One choice is to decompose using the violation D→B. Using the above FDs, we get BDE and ABC as decomposed relations. Using Algorithm 3.12 to discover the projection of FDs on relation BDE, we discover that BDE is in BCNF since D, BD, DE are the only keys and all the projected FDs contain D, BD, or DE in the left side. Going back to relation ABC, following Algorithm 3.12 tells us that ABC is not in BCNF because since AB and AC are its only keys and the FD C→B follows for ABC. Using violation C→B to further decompose, we get BC and AC as decomposed relations. Both BC and AC are in BCNF because they are two-attribute relations. Thus the three relations of the decomposition are BDE, BC and AC.

Exercise 3.3.2

Yes, we will get the same result. Both A→B and A→BC have A on the left side and part of the process of decomposition involves finding {A}+ to form one decomposed relation and A plus the rest of the attributes not in {A}+ as the second relation. Both cases yield the same decomposed relations.

Exercise 3.3.3

Yes, we will still get the same result. Both A→B and A→BC have A on the left side and part of the process of decomposition involves finding {A}+ to form one decomposed relation and A plus the rest of the attributes not in {A}+ as the second relation. Both cases yield the same decomposed relations.

Exercise 3.3.4

This is taken from Example 3.21 pg. 95.

Suppose that an instance of relation R only contains two tuples.

The projections of R onto the relations with schemas {A,B} and {B,C} are:

If we do a natural join on the two projections, we will get:

The result of the natural join is not equal to the original relation R.

Exercise 3.4.1a

This is the initial tableau:

A.

Since there is not an unsubscripted row, the decomposition for R is not lossless for this set of FDs.

We can use the final tableau as an instance of R as an example for why the join is not lossless. The projected relations are:

The joined relation is:

The joined relation has three more tuples than the original tableau. Exercise 3.4.1b

This is the initial tableau:

This is the final tableau after applying FDs AC→E and BC→D

Since there is an unsubscripted row, the decomposition for R is lossless for this set of FDs. Exercise 3.4.1c

This is the initial tableau:

This is the final tableau after applying FDs A→D, D→E and B→D.

Since there is an unsubscripted row, the decomposition for R is lossless for this set of FDs. Exercise 3.4.1d

This is the initial tableau:

This is the final tableau after applying FDs A→D, CD→E and E→D

Since there is an unsubscripted row, the decomposition for R is lossless for this set of FDs. Exercise 3.4.2

When we decompose a relation into BCNF, we will project the FDs onto the decomposed relations to get new sets of FDs. These dependencies are preserved if the union of these new sets is equivalent to the original set of FDs.

For the FDs of 3.4.1a, the dependencies are not preserved. The union of the new sets of FDs is CE→A. However, the FD B→E is not in the union and cannot be derived. Thus the two sets of FDs are not equivalent.

For the FDs of 3.4.1b, the dependencies are preserved. The union of the new sets of FDs is

AC→E and BC→D. This is precisely the same as the original set of FDs and thus the two sets of FDs are equivalent.

For the FDs of 3.4.1c, the dependencies are not preserved. The union of the new sets of FDs is

B→D and A→E. The FDs A→D and D→E are not in the union and cannot be derived. Thus the two sets of FDs are not equivalent.

For the FDs of 3.4.1d, the dependencies are not preserved. The union of the new sets of FDs is AC→E. However, the FDs A→D, CD→E and E→D are not in the union and cannot be derived. Thus the two sets of FDs are not equivalent.

Exercise 3.5.1a

In the solution to Exercise 3.3.1a we found that there are 14 nontrivial dependencies. They are: C→A, C→D, D→A, AB→D, AB→ C, AC→D, BC→A, BC→D, BD→A, BD→C, CD→A, ABC→D, ABD→C, and BCD→A.

We also learned that the three keys were AB, BC, and BD. Since all the attributes on the right sides of the FDs are prime, there are no 3NF violations.

Since there are no 3NF violations, it is not necessary to decompose the relation.

Exercise 3.5.1b

In the solution to Exercise 3.3.1b we found that there are 8 nontrivial dependencies. They are

B→C, B→D, AB→C, AB→D, BC→D, BD→C, ABC→D and ABD→C.

We also found out that the only key is AB. FDs where the left side is not a superkey or the attributes on the right are not part of some key are 3NF violations. The 3NF violations are B→C, B→D, BC→D and BD→C.

Using algorithm 3.26, we can decompose into relations using the minimal basis B→C and B→D. The resulting decomposed relations would be BC and BD. However, none of these two sets of attributes is a superkey. Thus we add relation AB to the result. The final set of decomposed relations is BC, BD and AB.

Exercise 3.5.1c

In the solution to Exercise 3.3.1c we found that there are 12 nontrivial dependencies. They are AB→C, BC→D, CD→A, AD→B, AB→D, AD→C, BC→A, CD→B, ABC→D, ABD→C, ACD→B and BCD→A.

We also found out that the keys are AB, AD, BC, and CD. Since all the attributes on the right sides of the FDs are prime, there are no 3NF violations.

Since there are no 3NF violations, it is not necessary to decompose the relation.

Exercise 3.5.1d

In the solution to Exercise 3.3.1d we found that there are 28 nontrivial dependencies. They are

A→B, B→C, C→D, D→A, A→C, A→D, B→D, B→A, C→A, C→B, D→B, D→C, AB→C, AB→D, AC→B, AC→D, AD→B, AD→C, BC→A, BC→D, BD→A, BD→C, CD→A, CD→B, ABC→D, ABD→C, ACD→B and BCD→A.

We also found out that the keys are A,B,C,D. Since all the attributes on the right sides of the FDs are prime, there are no 3NF violations.

Since there are no 3NF violations, it is not necessary to decompose the relation.

Exercise 3.5.1e

In the solution to Exercise 3.3.1e we found that there are 16 nontrivial dependencies. They are AB→C, DE→C, B→D, AB→D, BC→D, BE→C, BE→D, ABC→D, ABD→C, ABE→C,

ABE→D, ADE→C, BCE→D, BDE→C, ABCE→D, and ABDE→C.

We also found out that the only key is ABE. FDs where the left side is not a superkey or the attributes on the right are not part of some key are 3NF violations. The 3NF violations are

AB→C, DE→C, B→D, AB→D, BC→D, BE→C, BE→D, ABC→D, ABD→C, ADE→C,

BCE→D and BDE→C.

Using algorithm 3.26, we can decompose into relations using the minimal basis AB→C, DE→C and B→D. The resulting decomposed relations would be ABC, CDE and BD. However, none of these three sets of attributes is a superkey. Thus we add relation ABE to the result. The final set of decomposed relations is ABC, CDE, BD and ABE.

Exercise 3.5.1f

In the solution to Exercise 3.3.1f we found that there are 41 nontrivial dependencies. They are:

C→B, C→D, C→E, D→B, D→E, AB→C, AB→D, AB→E, AC→B, AC→D, AC→E, AD→B, AD→C, AD→E, BC→D, BC→E, BD→E, CD→B, CD→E, CE→B, CE→D, DE→B, ABC→D, ABC→E, ABD→C, ABD→E, ABE→C, ABE→D, ACD→B, ACD→E, ACE→B, ACE→D, ADE→B, ADE→C, BCD→E, BCE→D, CDE→B, ABCD→E, ABCE→D, ABDE→C and ACDE→B.

We also found out that the keys are AB, AC and AD. FDs where the left side is not a superkey or the attributes on the right are not part of some key are 3NF violations. The 3NF violations are

C→E, D→E, BC→E, BD→E, CD→E and BCD→E.

Using algorithm 3.26, we can decompose into relations using the minimal basis AB→C, C→D, D→B and D→E. The resulting decomposed relations would be ABC, CD, BD and DE. Since relation ABC contains a key, we can stop with the decomposition. The final set of decomposed relations is ABC, CD, BD and DE.

Exercise 3.5.2a

The usual procedure to find the keys would be to take the closure of all 63 nonempty subsets. However, if we notice that none of the right sides of the FDs contains attributes H and S. Thus we know that attributes H and S must be part of any key. We eventually will find out that HS is the only key for the Courses relation.

Exercise 3.5.2b

The first step to verify that the given FDs are their own minimal basis is to check to see if any of the FDs can be removed. However, if we remove any one of the five FDs, the remaining four FDs do not imply the removed FD.

The second step to verify that the given FDs are their own minimal basis is to check to see if any of the left sides of an FD can have one or more attributes removed without losing the dependencies. However, this is not the case for the four FDs that contain two attributes on the left side.

Thus, the given set of FDs has been verified to be the minimal basis.

Exercise 3.5.2c

Since the only key is HS, the given set of FDs has some dependencies that violate 3NF. We also know that the given set of FDs is a minimal basis. Thus the decomposed relations are CT, HRC, HTR, HSR and CSG. Since the relation HSR contains a key, we do not need to add an additional relation. The final set of decomposed relations is CT, HRC, HTR, HSR and CSG.

None of the decomposed relations violate BCNF. This can be verified by projecting the given set of FDs onto each of the decomposed relations. All of the projections of FDs have superkeys on their left sides.

Exercise 3.5.3

The usual procedure to find the keys would be to take the closure of all 63 nonempty subsets. However, if we notice that none of the right sides of the FDs contains attributes I and S. Thus we

know that attributes I and S must be part of any key. We eventually will find out that IS is the only key for the Stocks relation.

The first step to verify that the given FDs are their own minimal basis is to check to see if any of the FDs can be removed. However, if we remove any one of the four FDs, the remaining three FDs do not imply the removed FD.

The second step to verify that the given FDs are their own minimal basis is to check to see if any of the left sides of an FD can have one or more attributes removed without losing the dependencies. However, this is not the case for the one FD that contains two attributes on the left side.

Thus, the given set of FDs has been verified to be the minimal basis.

Since the only key is IS, the given set of FDs has some dependencies that violate 3NF. We also know that the given set of FDs is a minimal basis. Thus the decomposed relations are SD, IB, ISQ and BO. Since the relation ISQ contains a key, we do not need to add an additional relation. The final set of decomposed relations is SD, IB, ISQ and BO.

Exercise 3.5.4

This is the initial tableau:

This is the final tableau after applying FDs AB→C, C→B and A→D.

Since there is an unsubscripted row, the decomposition for R is lossless for this set of FDs. Exercise 3.5.5

Suppose that our relation relates to the work environment and has three attributes, Name, RoomNumber and ComputerID. Suppose also that only the following FDs hold: Name→RoomNumber

ComputerID→RoomNumber

The first FD says that a person can only be in one office at a time. The second FD says that each computer can only be associated with one office at a time (i.e. the computer is fixed to each room). None of the left sides of the FDs are keys and the respective right side attributes do not belong to any key. Using algorithm 3.20 to decompose, we take the violating FD

Name→RoomNumber and use it to decompose the initial relation into two smaller relations: R1(Name,RoomNumber)

R2(Name,ComputerID)

We do not need to further decompose the two relations so we are done. However, we have lost the FD ComputerID→RoomNumber with this decomposition. Suppose that ‘John Doe’ works in room number ‘1’. Suppose also that computer ID ‘A’ is located in room ‘1’. The original relation would contain the tuple:

{‘John Doe’, 1, ‘A’}

If we follow the decomposition, we would expect the tuple above to be broken into two smaller tuples:

{‘John Doe’, 1}

{‘John Doe’, ‘A’}

Suppose that ‘John Doe’ moves to room 2 and ‘Jane Doe’ moves into room 1 and that ‘Jane Doe’ is using computer ID ‘A’. The following tuples would be in the respective relations: {‘John Doe’, 2}

{‘Jane Doe’, 1}

{‘John Doe’, ‘A’}

{‘Jane Doe’, ‘A’}

If we were to join back the two relations, we would get:

{‘John Doe’, 2, ‘A’}

{‘Jane Doe’, 1, ‘A’}

which violates the FD ComputerID→RoomNumber

Exercise 3.6.1

Since A B, and all the tuples have the same value for attribute A, we can pair the B-value from any tuple with the value of the remaining attribute C from any other tuple. Thus, we know that R must have at least the nine tuples of the form (a,b,c), where b is any of b1, b2, or b3, and c is any of c1, c2, or c3. That is, we can derive, using the definition of a multivalued dependency, that each of the tuples (a,b1,c2), (a,b1,c3), (a,b2,c1), (a,b2,c3), (a,b3,c1), and (a,b3,c2) are also in R.

First, people have unique Social Security numbers and unique birthdates. Thus, we expect the functional dependencies ssNo→name and ssNo→birthdate hold. The same applies to children, so we expect childSSNo→childname and childSSNo→childBirthdate. Finally, an automobile has a unique brand, so we expect autoSerialNo→autoMake.

There are two multivalued dependencies that do not follow from these functional dependencies. First, the information about one child of a person is independent of other information about that person. That is, if a person with social security number s has a tuple with cn,cs,cb, then if there is any other tuple t for the same person, there will also be another tuple that agrees with t except that it has cn,cs,cb in its components for the child name, child Social Security number, and child birthdate. That is the multivalued dependency

ssNochildSSNo→→childName childBirthdate

Similarly, an automobile serial number and make are independent of any of the other attributes, so we expect the multivalued dependency

ssNo→→autoSerialNo autoMake

The dependencies are summarized below:

ssNo → name, birthdate

childSSNo → childName, childBirthdate

autoSerialNo → autoMake

ssNo →→ childSSNo, childName, childBirthdate

ssNo →→ autoSerialNo, autoMake

Exercise 3.6.2b

We suggest the relation schemas:

{ssNo, name, birthdate}

{ssNo, childSSNo}

{childSSNo, childName childBirthdate}

{ssNo, autoSerialNo}

{autoSerialNo, autoMake}

An initial decomposition based on the two multivalued dependencies would give us:

{ssNo, name, birthDate}

{ssNo, childSSNo, childName, childBirthdate}

{ssNo, autoSerialNo, autoMake}

Functional dependencies force us to decompose the second and third of these.

数据库试题和答案

试题一 一、单项选择 1.对于现实世界中事物的特征,在实体-联系模型中使用() A)属性描述B)关键字描述C)二维表格描述D)实体描述 2.把实体-联系模型转换为关系模型时,实体之间多对多联系在关系模型中是通过()A)建立新的属性来实现B)建立新的关键字来实现 C)建立新的关系来实现D)建立新的实体来实现 3.专门的关系运算不包括下列中的() A)联接运算(两个关系横向连接)B)选择运算(从行抽取) C)投影运算(从列抽取)D)交运算 4.对关系S和关系R进行集合运算,结果中既包含S中元组也包含R中元组,这种集合运算称为 A)并运算B)交运算C)差运算D)积运算 5.在数据库设计中,将ER图转换成关系数据模型的过程属于() A)需求分析阶段B)逻辑设计阶段 C)概念设计阶段D)物理设计阶段 6.对于关系数据库,任何二元关系模式最高都可以达到范式。 A)1NF B)2NF C)3NF D)BCNF 7.在概念设计阶段,最常使用的数据模型是() A)对象模型B)物理模型C)逻辑模型D)实体联系模型 8.下面有关索引的描述正确的是() A)创建非聚集索引以后,原来的数据库表文件中记录的物理顺序将被改变(不被改

变) B)索引与数据库表的数据存储在一个文件中(创建一个新的文件) C)创建非聚集索引是创建一个指向数据库表文件记录的指针构成的文件 D)使用索引并不能加快对表的查询操作(能加快) 9.关系R1和R2,经过关系运算得到结果是S,则S 是 A)一个关系B)一个表单C)一个数据库D)一个数组 10.子模式是用户与数据库的接口之一,它对应于数据库的 A)外模式B)概念模式C)内模式D)存储模式 11.已知关系R(A,B,C,D,E)及其上的函数相关性集合,F={A→B,E→A,CE→D},该关系的候选关键字是 A)AE B)BE C)CE D)DE 12.设有关系R(A,B,C,D)及其上的函数相关性集合F={B→A,BC→D},那么关系R最高是A)第一范式的B)第二范式的C)第三范式的D)BCNF范式的13.如果学生表STUDENT是使用下面的SQL语句创建的CREATE TABLE STUDENT(SNO CHAR(4) PRIMARY KEY NOT NULL,SN CHAR(8),SEX CHAR(2),AGE DECIMAL(2) CHECK(AGE>15 AND AGE<30)) 下面的SQL语句中不可以正确执行的是 A)INSERT INTO STUDENT(SNO,SEX,AGE) valueS ("S9","男",17) B)INSERT INTO STUDENT(SNO,SEX,AGE) valueS ("李安琦","男",20) C)INSERT INTO STUDENT(SEX,AGE) valueS ("男",20) D)INSERT INTO STUDENT(SNO,SN) valueS ("S9","安琦") 14.设有部门和职员两个实体,每个职员只能属于一个部门,一个部门可以有多名职员。

数据库应用试卷及答案

; 数据库及应用(B卷) 一、选择题(从备选答案中选1 个正确的答案,每题2分、共24分) 1.支持所有用户建立、存储数据库的软件系统是。 A.数据库系统 B.数据库管理系统 C.应用程序 D.操作系统2.DB的三级模式结构中最接近外部存储器的是。 A.子模式 B.外模式 C.概念模式 D.内模式 3.在关系模式R中,函数依赖X→Y的语义是。 A.在R的某一关系中,若两个元组的X值相等,则Y值也相等: B.在R的每一关系中,若两个元组的X值相等,则Y值也相等 C.在R的某一关系中,Y值应与X值相等 D.在R的每一关系中,Y值应与X值相等 4. DBA是________的简称。 A.系统分析员 B.应用程序员 C.数据库管理员 D.数据录入员 5. _____是长期存储在计算机内的有组织,可共享的数据集合. A.数据库管理系统B.数据库系统 C.数据库D.文件组织6.数据库系统的核心是。 《 A. 数据库 B. 数据库管理系统 C. 数据模型 D. 软件工具 7.客观存在并可相互区别的事物叫________。 A.码 B.属性 C.实体 D. 实体集8.数据库的完整性是指数据的_____和_____。 (1)正确性(2)合法性(3)不被非法存取 (4)相容性 (5)不被恶意破坏 A. (1)和(3) B. (2)和(5) C. (1)和(4) D. (2)和(4) 9.一组具有相同数据类型的值的集合称为________。 \ A.关系 B.属性 C.分量 D.域 10.以下______封锁违反两段锁协议。 A.Slock A … Slock B … Xlock C …… Unlock A … Unlock B … Unlock C B.Slock A … Slock B … Xlock C …… Unlock C … Unlock B … Unlock A C.Slock A … Slock B … Xlock C …… Unlock B … Unlock C … Unloc k A D.Slock A …Unlock A …Slock B … Xlock C …… Unlock B … Unlock C 11. “日志”文件用于保存________。

数据库原理试题及答案

数据库原理试题答案(B卷) 一、填空题(每题 2 分,共 20 分) 1、实体 2、日志文件 3、完整性 4、关系 5、关系演算 6、外模式 / 模式 7、更新 8、集成的 9、先来先服务 10、人工智能 二、选择题(每题 1 分) 1 、C 2 、 D 3 、 B 4 、 A 5 、 B 6 、 C 7 、 C 8 、 C 9 、 B 10 、 C 三、简答题(每题 5 分,共 20 分) 1 、答案要点:数据库系统中的常见故障有:事务内部的故障(事务故障)( 1 分)、系统故障( 1 分)、介质故障( 2 分)、计算机病毒( 1 分)。 2 、答案要点:数据模型通常由数据结构( 1 分)、数据操作( 2 分)、完整性约束( 2 分)三部分组成。 3 、答案要点:不是所有的视图都是可更新的( 2 分);因为有些视图的更新不能唯一地有意义地转换成对相应基本表地更新( 3 分)。 4 、答案要点:多个事务的并发执行是正确的,当且仅当其结果与按某一次序串行执行它们时的结果相同( 5 分)。 四、(共 10 分) 1 、 80 , 90 2 、 T 1 T 2 Slock A 读 A = 50 Y = A Unlock A Xlock A A=Y-10 Slock A 写回 A = 40 等待 Unlock A 等待 读 A = 40 Y = A Unlock A Xlock A A=Y × 2 写回 A = 80 Unlock A

五、(共 10 分) 六、(共 20 分) 1 、关系代数: (1)sno ( cno =‘ 2 ' (SC) )(2分) (2) Sno,Sn ( Cn=' 数据库概论 ' ) (2分) (3) Sno,SN (S ( Cno , sno (SC) ÷ Cno ( C )) ) (2分) ALPHA 语言 ? GET W(SC.SNO): https://www.sodocs.net/doc/3911731418.html,O=' 2' (2分) ? RANGE C X SC Y GET W (S.SNO.S.SN): X( Y(https://www.sodocs.net/doc/3911731418.html,O=https://www.sodocs.net/doc/3911731418.html,O ^ Y.SNO=S.SNO ^ https://www.sodocs.net/doc/3911731418.html,=' 数据库概论 ' (2分) ? RANGE C X SC Y GET W(S.SNO,S.SN): X( Y(https://www.sodocs.net/doc/3911731418.html,O=https://www.sodocs.net/doc/3911731418.html,O ^ Y.SNO=S.SNO)) (2分) 2 、( 1 ) SELECT COUNT(*) FROM STUDENT (2分) (2) SELECT SNO FROM SC GROUP BY SNO HAVING COUNT(*)>5 (3分) (3) DELECT FROM SC WHERE https://www.sodocs.net/doc/3911731418.html,O IN (SELECT https://www.sodocs.net/doc/3911731418.html,O FROM C WHERE CN=' 数据结构 ') DELETE FROM C WHERE CN= ‘数据结构' (3分) 七、(共 10 分) 科室(科室代码,科室名称) (1分) 医生(工号,姓名,名称,聘用日期,聘用期限,科室) (1分) 病人(病历号,姓名,年龄,工作单位) (1分) 就诊(医生工号,病历号,就诊日期) (2分) 一、填空题(每空 2 分,共 20 分) 1、关系中主码的取值必须唯一且非空,这是由 ___________ 完整性规则决定的。 2、当数据库被破坏后,如果事先保存了数据库副本和 ________________ ,就有可能恢复数据库。 3、数据库的 ____________ 是指数据库的正确性和相容性。 4、关系数据操作语言的特点是:操作对象与结果均为 ___________ 、操作的非过程性强、语言一体化、并且建立在数学理论基础之上。 5、SQL 是一种介于关系代数和 _____________ 之间的结构化的查询语言。 6、对于每一个外模式,数据库系统都有一个 _______________ 映象,它定义了该外模式与模式之间的对应关系。 7、视图是一个需表,它一经定义就可以和基本表一样被查询,但 _________ 操作将有一定的限制。 8、数据仓库是一个面向主题的、 _____________ 、不可更新的、随时间不断变化的数据集合。 9、避免活锁的简单方法是采用 _____ 的策略。 10、知识库系统和主动数据库系统是将数据库技术和 ________ 技术相结合产生的。 二、选择题(每小题 1 分,共 10 分) 1、SQL 中,下列涉及空值的操作,不正确的是 ( )

数据库实验3答案

实验三:交互式SQL语句的使用 1、实验目的 (1)掌握数据库对象的操作过程,包括创建、修改、删除 (2)熟悉表的各种操作,包括插入、修改、删除、查询 (3)熟练掌握常用SQL语句的基本语法 2、实验平台 使用SQL Server提供的Microsoft SQL Server Management Studio工具,交互式使用SQL语句。 3 实验容及要求 选择如下一个应用背景之一: ●学生选课系统 ●习题3、4、和5中使用的数据库 ●其它你熟悉的应用 (1)建立一个数据库和相关的表、索引、视图等数据库对象,练习对表、索引和视图的各种操作。 (2)要求认真进行实验,记录各实验用例及执行结果。 (3)深入了解各个操作的功能。 实验要求包括如下方面的容: 3.1 数据定义 1.基本表的创建、修改及删除 2.索引的创建 3.视图的创建 3.2 数据操作 完成各类更新操作包括: 1.插入数据

2.修改数据 3. 删除数据 3.3 数据查询操作 完成各类查询操作 1.单表查询 2.分组统计 3. 连接查询 4. 嵌套查询 5. 集合查询 3.4 数据操作 1.创建视图 2.视图查询 参考示例: 建立一个学生选课数据库,练习对表、视图和索引等数据库对象的各种操作。 一、数据定义 创建学生选课数据库ST,包括三个基本表,其中Student表保存学生基本信息,Course表保存课程信息,SC表保存学生选课信息,其结构如下表: 表1. Student表结构 表2. Course表结构

表3. SC表结构 1.创建、修改及删除基本表 (1)创建Student表 CREATE TABLE Student (Sno CHAR(8)PRIMARY KEY, Sname CHAR(8), Ssex CHAR(2)NOT NULL, Sage INT, Sdept CHAR(20) ); (2)创建Course表 CREATE TABLE Course (Cno CHAR(4)PRIMARY KEY, Cname CHAR(40)NOT NULL, Cpno CHAR(4), Ccredit SMALLINT, ); (3)创建SC表 CREATE TABLE SC (Sno CHAR(8)FOREIGN KEY (Sno)REFERENCES Student(Sno), Cno CHAR(4), Grade SMALLINT, ); (4)创建员工表Employee

数据库考题及答案参考

一、填空和选择 1.数据库管理产生和发展的三个阶段Page: 6 人工管理阶段、文件系统阶段、数据库系统阶段 2.视图的概念page 118 视图是从一个或几个基本表(虚表),视图一经定义,就可以和基本表一样被查询,被删除,也可以在一个视图之上在定义新的视图,但对视图的更新操作则有一定的限制 3.关系模型的三类完整性约束page 30 实体完整性、参照完整性、和用户定义性的完整性 4.关系运算运算中的两种特殊符号%百分号,_ 下划线page 96 5.四类数据逻辑模型page 18 逻辑模型主要包括:层次模型/网状模型(格式化模型)、关系模型、面向对象模型、对象关系模型 6.关系模型的三个组成部分page 338 数据结构、关系操作、数据完整性 7.数据字典包含的五个组成部分page 207 数据项、数据结构、数据流、数据存储、处理过程5个部分;其中数据项是数据的最小组成单位,若干数据项可以组成一个数据结构,数据字典通过对数据项和数据结构的定义来描述数据流,数据存储的逻辑内容 8.两种数据操作类型page 12 概念模型一信息模型;(按用户的观点来对数据和信息建模,用于数据库设计) 逻辑模型(按计算机系统的观点对数据建模,主要用于DBMS的实现) 9.数据库系统和文化系统的区别page 7~9 数据库系统实现整体数据的结构化,这事数据库的主要特征之一,也是数据库系统与文件系统的本质区别 Page6的表也可以参照! 10.数据库设计过程的六个阶段(注意ER图转换)page 201 需求分析、概念结构设计、逻辑结构设计、物理结构设计、数据库实施、数据库运行和维护 11.关系模型的几个概念page 28 关系模型是目前最重要的一种数据模型。关系数据库系统采用关系模型作为数据组织方式 关系:relation 一个关系对应通常说的一张表 元组tuple: 表中的一行,即一个元组

数据库试题及答案

《数据库》试题 使用教材:Visual FoxPro 数据库应用 试题范围:全册 出版社:高等教育出版时版次:第3版 学校名称:文县职业中专 一、选择题 1、在有关数据库的概念中,若干记录的集合称为() A. 文件 B. 字段 C. 数据项 D. 表 2、在Visual FoxPro中,向数据库文件中追加数据使用语句() A、INSERT B、REPLACE C、APPEND D、ADD 3、在Visual FoxPro中,删除数据库的所有记录,仅保留库结构的命令是( ) A、delete all B、pack C、recall D、zap 4、在Visual FoxPro中,分屏显示当前数据库中年龄字段大于20的所有记录,正确的命令为( ) A、display all for nl>20 B、display all while nl>20 C、list for nl while nl>20 D、list while nl>20 5、在Visual FoxPro中,skip命令移动记录指针的基准是( ) A、第一条记录 B、当前记录 C、指定纪录 D、库文件尾6、逻辑运算符在运算时的优先顺序是() A.NOT→AND→OR B.AND→NOT→OR C.OR→NOT→AND D.从左至右按先后次序 7、在关系运算中,查找满足一定条件的元组的运算称之为()A. 投影 B. 选择 C. 关联 D. 复制 8、下面的赋值表达式不正确的是() A.STORE "HELLO WORLD!" TO STR B. STORE 123456 TO

A1,B1 C.WORD="FOXPRO" D.STORE 12,34 TO A2,B29、不能作为索引关键字的数据类型是() A.数值型 B.备注型 C.日期型 D.字符型 10、当前表中含xm(姓名,字符型)字段,显示姓“李”的记录的命令是() A.DISP FOR "李"=xm B.DISP FOR xm=李 C.DISP FOR SUBS(xm,1,1)= ‘李’ D.DISP FOR SUBS(xm,1,2)=‘李’ 11、用命令DIMENSION A(4,5)定义后,A数组中共有()个数据元素。 A. 4 B. 5 C. 9 D. 20 12、在Visual FoxPro的一个工作区中,同一时刻最多能打开( )个库文件。 A、10 B、1 C、任意多 D、256 13、33.结构化程序设计中的三种基本结构是顺序结构、分支结构和() A、选择结构 B、循环结构 C、混合结构 D、跳转结构 14、假定STUDENT.DBF学生数据库文件中前六条记录均为男生的记录,执行以下命令序列: USE.STUDENT GOTO 3 LOCATE NEXT 3 FOR 性别="男" 后,记录指针定位在( ) A、第3条记录上 B、第4条记录上 C、第5条记录上 D、第6条记录上 15、68.下面有关表索引的几种说法,正确的是() A.索引和排序一样,它改变记录的物理顺序。

数据库试题及答案_

笔试样卷一 参考答案 一、简答题(25分) 1.数据库阶段数据管理的主要特点是什么? 2.解释DB、DBMS、DBS三个概念? 3.什么是物理数据独立性和逻辑数据独立性? 4.试说明DBMS的主要功能? 5.在ER模型转换为关系模型时,联系类型要根据不同的情况作不同的处理,试说明之。 二、计算题(20分) 1.设有关系R和S R: S: A B C A B C 3 6 7 3 4 5 2 5 7 7 2 3 7 3 4 4 4 3 列表计算R∪S、R-S、R×S、π 3,2(S)、δ B<5 (R)。(5分) 2.设有三个关系 S (SNO, SNAME, AGE, SEX, SDEPT) SC (SNO, CNO, GRANDE) C (CNO, CNAME, CDEPT, TNAME) 试用关系代数表达式表示下列查询

(1)检索LIU老师所授课程的课程号、课程名 (2)检索年龄大于23岁的男学生的学号和姓名 (3)检索学号为S3的学生所学课程的课程名和认课教师姓名 (4)检索WANG同学不学的课程的课程号 (5)检索至少选修了两门课程的学生的学号(10分) 三、设有三个基本表(45分) S (SNO, SNAME, AGE, SEX, SDEPT) SC (SNO, CNO, GRANDE) C (CNO, CNAME, CDEPT, TNAME) 1.试用T-SQL的查询语句表达下列查询 (1)检索LIU老师所授课程的课程号、课程名 (2)检索年龄大于23岁的男学生的学号和姓名 (3)检索学号为S3的学生所学课程的课程名和认课教师姓名 (4)检索WANG同学不学的课程的课程号 (5)检索至少选修了两门课程的学生的学号(10分) 2.试用T-SQL的查询语句表达下列查询 (1)统计有学生选修的课程的门数 (2)求选修C4课程的学生的年龄 (3)求LIU老师所授课程的每门课程的学生的平均成绩 (4)统计每门课程的学生选修人数 (5)求年龄大于所有女同学年龄的男学生的姓名和年龄(10分)3.试用T-SQL更新语句完成下列更新操作 (1)往表S中插入一个学生资料(‘S9’, ‘WU’, 18)

同济大学数据库实验5答案

create proc procA as select* from student exec proca create proc procB @_year char(4) as select* from student where year(birthday )=@_year declare @_year char(4) set @_year ='1994' exec procB@_year create proc procf @_Snum char(30) as select s.snum ,avg(score)as平均成绩,count(https://www.sodocs.net/doc/3911731418.html,um)as选秀门数,sum(1-score/60)as不及格门数 from student s,course c,sc,sections st where s.snum =sc.snum and sc.secnum =st.secnum and https://www.sodocs.net/doc/3911731418.html,um =https://www.sodocs.net/doc/3911731418.html,um and S.Snum =@_Snum group by S.Snum DECLARE @_SUNM char(30) set @_SUNM ='s001' exec procf@_sunm CREATE PROC Procd @_snum char(4),@_avg int out,@_selected_course int out,@_failed_course int out AS SELECT @_avg=AVG(score),@_selected_course=COUNT(cnum),@_failed_course=sum(1-score/60) FROM sc JOIN sections ON sc.secnum =sections.secnum WHERE snum=@_snum

数据库作业题目及答案

实验三内容补充 在“教学管理系统”中设计了许多查询,上述只介绍其中具有代表性的部分,其余查询读者可依例完成。本系统包括的所有查询如下所示: 说明:同学们在进行后面的表单设计时,需要用到没有设计过的查询,则再进行对应的查询设计,没有设计到的可以不做。 1.90 以上学生信息 2.按班查不及格学生 3.按班级编号查看学生基本信息 4.按班级查教师信息 5.按班级查选课 6.按教师编号查 7.按教师姓名查看授课信息 8.按课程类别查 9.按课程名查 10.按上课地点查 11.按所选课程查 12.按系名查 13.按姓名查看学生基本信息 14.按学分查 15.按学号查看学生基本信息 16.按学号查选课 17.按职称查 18.不及格人次 19.不及格学生信息 20.低于所在班平均分学生 21.各班学生人数统计 22.各系教师人数 23.各职称教师人数 24.教师基本信息表查询 25.教师每周学时总数 26.每班不及格人次 27.每班每门课平均成绩 28.每班男女生人数 29.每班平均成绩 30.每班平均分 31.每名学生平均成绩 32.某学年某学期教师每周学时总数 33.某学期某课不及格信息 34.统计各系教师的人数 35.统计各职称教师的人数 36.统计每门课教师的人数 37.统计有课教师的人数 38.学生相关信息查询 39.学生选课情况 40.有课教师的人数

实验四数据登录窗体设计一 4.1数据登录窗体的向导创建 在Access中创建窗体有人工方式创建和使用窗体向导创建两种方法。人工方式创建窗体,需要创建窗体的每一个控件,并建立控件和数据源之间的联系。而使用窗体向导创建窗体,用户只需按照向导的提示输入有关信息,一步一步地完成。创建过程既简单、快捷,又效率高,因此,在设计Access数据库应用系统时,往往是先使用窗体向导建立窗体的基本轮廓,然后再切换到设计视图使用人工方式进行调整。我们在创建“登录教师档案”窗体时采用的就是这种方法。 利用窗体向导创建“登录教师档案”,窗体的步骤如下: ①双击“窗体”对象中“使用向导创建窗体”选项,启动“窗体向导”如图2-1所示。 图2-1“窗体向导”第一个窗口 ②单击“表/查询”下拉列表框右侧的箭头,列出所有有效的表或者查询数据源,从中选择“表:教师档案表”。 ③在“可用字段”列表框中选择需要在新建窗体中显示的字段,此处,单击按钮选择所有字段。 ④单击“下一步”按钮,弹出如图2-2所示的窗口。在此对话框中,选择“纵栏表”项,这时可以在左边看到所建窗体的布局。

数据库习题及答案,第三版

2004-2005学年第二学期期末考试 D 2002级计算机科学与技术专业《数据库原理与应用》课程试题 一、选择题(15分,每空1分): 1 .数据库系统中,物理数据独立性( physical data independenee )是指 _ 。 A. 数据库与数据库管理系统的相互独立 B. 应用程序与DBMS 的相互独立 C. 应用程序与存储在磁盘上数据库的物理模式是相互独立的 D. 应用程序与数据库中数据的逻辑结构相互独立 2. _____________________ 数据库系统的特点是 、数据独立、减少数据冗余、避免数据不一 致和加强了数据保护。 A. 数据共享 B .数据存储 C.数据应用 D .数据保密 3. 数据库管理系统能实现对数据库中数据的查 询、 插入、修改和删除等操作的数据库语言称为 A. 数据定义语言(DDL ) B .数据管理语言 C.数据操纵语言(DML ) D .数据控制语言 4. 在关系代数的专门关系运算中,从表中取出满足条件的属性的操作称为①;从表中选出满足某种 条件的元组的操作称为②;_将两个关系中具有共同属性值的元组连接到一起构成新表的操作称为③。 A. 选择 B .投影 C.连接 D.扫描 5. _________________________ 关系模型中,一个候选码 。 A .可由多个任意属性组成 B. 至多由一个属性组成 C. 可由一个或多个其值能唯一标识该关系模式中任何元组的属性组成 D. 必须由多个属性组成 7.数据库中只存放视图的 __________ 。 A .操作 B .对应的数据 C. 定义 D.限制 9.数据库管理系统通常提供授权功能来控制不同用户访问数据的权限, O A. 可靠性 B. —致性 C.完整性 D .安全性 6. SQL 语言是 语言。 A .层次数据库 C .关系数据库 B. 网络数据库 D .非数据库 &关系数据库规范化是为解决关系数据库中 问题而引人的。 A .数据冗余 B. 提高查询速度 C.减少数据操作的复杂性 D .保证数据的安全性和完整性 这主要是为了实现数据库的

sql 数据库 实验3答案

实验三:创建及管理数据表 1、创建表 依据数据表的结构创建相对应的数据表,表结构如下所示; 学生信息表(student ) CREATE (sno char (9) PRIMARY KEY , sname char (8) NOT NULL, ssex char (2), sage int , sdept varchar (20) ) 课程信息表(course ) CREATE (cno char (4) PRIMARY KEY , cname varchar (20) NOT NULL, cpno char (4), ccredit int ) 选课信息表(sc )

CREATE TABLE sc (sno char(9), cno char(4), grade int, Constraint PK_sno PRIMARY KEY(sno,cno)) 2.修改表结构 1)在表student中增加新字段“班级名称(sclass)”字符类型为varchar(10); use student ALTER TABLE student Add sclass nvarchar(10) 2)在表student中删除字段“班级名称(sclass)”; use student ALTER TABLE student Drop column sclass 3)修改表student中字段名为“sname”的字段长度由原来的6改为8; use student ALTER TABLE student ALTER COLUMN sname char(8) 4)修改表student中ssex字段默认值为‘男’; use student ALTER TABLE student add default'男'for ssex 5)修改表course中cname字段为强制唯一性字段; use student ALTER TABLE course Add constraint ix_course unique (cname) 6)修改表sc中grade字段的值域为0-100; use student ALTER TABLE sc Add constraint CK_grade CHECK(grade between 0 and 100) 7)删除数据表course的唯一性约束; use student ALTER TABLE course drop ix_course

数据库期末试题(附答案)

《数据库原理》课程考试模拟题四 一、单项选择题(在每小题的四个备选答案中选出一个正确答案。本题共16分,每小题1分) 1. 在数据库中,下列说法()是不正确的。 A.数据库中没有数据冗余 B.数据库具有较高的数据独立性 C.数据库能为各种用户共享 D.数据库加强了数据保护 2. 按照传统的数据模型分类,数据库系统可以分为( )三种类型。 A.大型、中型和小型 B.西文、中文和兼容 C.层次、网状和关系 D.数据、图形和多媒体 3. 在数据库的三级模式结构中,( )是用户与数据库系统的接口,是用户用到的那部分数据的描述。 A.外模式 B.内模式 C.存储模式 D.模式 4. 下面选项中不是关系的基本特征的是( )。 A. 不同的列应有不同的数据类型 B. 不同的列应有不同的列名 C. 没有行序和列序 D. 没有重复元组 5. SQL语言具有两种使用方式,分别称为交互式SQL和( )。 A.提示式SQL B.多用户SQL C.嵌入式SQL D.解释式SQL 6. 设关系模式R(ABCD),F是R上成立的FD集,F={A→B,B→C},则(BD)+为( )。 A.BCD B.BC C.ABC D.C 7. E-R图是数据库设计的工具之一,它适用于建立数据库的( )。 A.概念模型 B.逻辑模型 C.结构模型 D.物理模型 8. 若关系模式R(ABCD)已属于3NF,下列说法中( )是正确的。 A.它一定消除了插入和删除异常 B.仍存在一定的插入和删除异常 C.一定属于BCNF D.A和C都是 9. 解决并发操作带来的数据不一致性普遍采用( )。 A.封锁技术 B.恢复技术 C.存取控制技术 D.协商 10. 数据库管理系统通常提供授权功能来控制不同用户访问数据的权限,这主要是为了实现数据库的( )。 A.可靠性 B.一致性 C.完整性 D.安全性 11. 一个事务一旦完成全部操作后,它对数据库的所有更新应永久地反映在数据库中,不会丢失。这是指事务的( ) 。 A. 原子性 B. 一致性 C. 隔离性 D. 持久性 12. 在数据库中,软件错误属于( )。 A. 事务故障 B. 系统故障 C. 介质故障 D. 活锁 13. 在通常情况下,下面的关系中不可以作为关系数据库的关系是( )。 A.R1(学生号,学生名,性别) B.R2(学生号,学生名,班级号) C.R3(学生号,学生名,宿舍号) D.R4(学生号,学生名,简历) 14. 有12个实体类型,并且它们之间存在着15个不同的二元联系,其中4个是1:1联系类型,5个是1:N

数据库试题及答案汇编

《数据库技术与应用》样题 一、选择题( 共 30 分,1--20 每小题 1 分,21—25 每小题 2 分。下列各题 A )、B)、 C)、D)四个选项中,只有一个选项是正确的 ) 1 在 SQL Server 中,关于视图的正确叙述是 A)视图与数据库表相同,用来存储数据B)视图不能同数据库表进行连接操作 C)在视图上不能进行更新操作D)视图是从一个或多个数据库表导出的虚拟表 2 SQL 是那几个英文单词的缩写 A)Standard Query LanguageB)Structured Query Language C) Select Query LanguageD)以上都不是 3 不属于 SQL Server 系统全局变量的是()。 A 、@@ErrorB 、@@ConnectionC 、@@Fetch_StatusD 、@Records 4 下面描述错误的是() A 、每个数据文件中有且只有一个主数据文件 B 、日志文件可以存在于任意文件组中 C 、主数据文件默认为 primary 文件组 D 、文件组是为了更好地实现数据库文件组织 5 SQL Server 数据库文件有三类,其中主数据文件的后缀为( ) A 、.mdfB 、.ldfC 、.ndfD 、.idf 6、下面标识符不合法的是( ) A 、[my delete]B 、_mybaseC 、$moneyD 、trigger1 7 下面字符串能与通配符表达式[ABC]%a 进行匹配的是() A 、BCDEFB 、A_BCDC 、ABC_aD 、A% 8、下面对索引的相关描述正确的是()列值唯一的列适合间索引 A 、经常被查询的列不适合建索引B 、列值惟一的列适合建索引 C 、有很多重复值的列适合建索引D 、是外键或主键的列不适合建索引 9、在“连接”组中有两种连接认证方式,其中在( )方式下,需要客户端应用程序连接 时提供登录时需要的用户标识和密码。 A 、Windows 身份验证B 、SQL Server 身份验证 C 、以超级用户身份登录时D 、其他方式登录时 10、索引是在基本表的列上建立的一种数据库对象,它同基本表分开存储,使用它能够加快 数据的( )速度。 A 、插入B 、修改C 、删除D 、查询 在where 子句中出现频率较高的列应尽量创建索引 11、以下哪种情况应尽量创建索引( ) A 、在 Where 子句中出现频率较高的列B 、具有很多 NULL 值的列 C 、记录较少的基本表D 、需要更新频繁的基本表 12、域完整性用于保证给定字段中数据的有效性,它要求表中指定列的数据具有正确的数据 类型、格式和有效的( )。 A 、数据值B 、数据长度C 、取值范围D 、以上都不是 13 以下不属于表之间定义关系的是 A)一对一关系B) 一对多关系C) 多对多关系D) 少对多关系 14 目前数据库有三种基本的数据模型是 ________ 。 A 、 层次模型、网络模型、关系模型B 、对象模型、网络模型、关系模型 网络模型、对象模型、层次模型D 、层次模型、关系模型、对象模型 15 从“产品”表里查询出价格高于产品名称为“海天酱油”的产品的记录,此 SQL 语句为 A 、SELECT * FROM 产品WHERE 价格>海天酱油

数据库试题及答案_两套[1]

数据库试题及答案两套收藏 数据库原理试题(A卷) 一、填空题(每空 1 分,共 20 分) 1. 对于一个国家来说,数据库的建设规模、数据库信息量的 _安全性____________ 和 ____完整性_________ 已成为这个国家信息化程度的 _______衡量标准_________ 。 2. 数据模型通常由: ___数据结构_____________ 、_______数据操作_________ 和 __完整性约束___________ 三部分组成。 3. 游标的功能是把 __集合记录______________ 转换为 ___单记录_____________ 。 4. 最常用的数据库的恢复技术是_数据转储____________ 和 _登记日志文件__________。 5. __概念_____ 模型是现实世界到 __数据模型___________ 机器模型的中间桥梁。 6. 数据独立性是指___物理________ 和__逻辑___________ 独立性。 7. 数据库应用程序开发工具目前有_ C++, _____________ 、__________VB_______ 、_______DEF_________ 、和 ____________C#____ 等。 8. 目前数据库产品有 SQL Server 和 ____ORACLE____________ 、 ___ACESS_____________ 等。 二、选择题(每小题 1 分,共 10 分) 1. 关于冗余数据的叙述中,不正确的是 (C ) 。 A .冗余的存在容易破坏数据库的完整性 B .冗余的存在给数据库的维护增加困难. C .不应该在数据库中存储任何冗余数据 D .冗余数据是指可由基本数据导出的数据 2. 概念模型独立于 (C ) 。 A . ER 模型 B .硬件设备 C . DBMS D .操作系统 3. 下列叙述正确的为(D )。 A. 主码是一个属性,它能唯一表识一列 B. 主码是一个属性,它能唯一表识一行 C. 主码是一个属性或属性集,它能唯一表识一列 D. 主码是一个属性或属性集,它能唯一表识一行 4. 数据库三级模式体系结构的划分,有利于保持数据库的 (A ) 。 A .数据独立性 B .数据安全性 C .结构规范化 D .操作可行性 5. 一个关系中的候选关键字(B )。 A .至多一个 B .可多个 C .必须多个 D .至少 3 个 6. 常用的关系运算是关系代数和(C )。 A .集合代数 B .逻辑演算 C .关系演算 D .集合演算 7. 在基本层次联系中,记录型之间的联系是(D )。 A .一对一联系 B .一对多联系 C .多对多联系 D .多对一联系 8. 并发操作会带来哪些数据不一致性(D )。 A .不可修改、不可重复读、脏读、死锁 B .不可重复读、脏读、死锁 C .丢失修改、脏读、死锁 D .丢失修改、不可重复读、脏读 9. 在数据库与宿主语言之间传递信息是通过(A )。 A. 全局变量 B. 共性变量 C. 公共数据区 D. 系统缓冲区 10. 数据库的(B )是指数据的正确性和相容性。 A. 安全性 B. 完整性 C. 并发控制 D. 恢复 三、判断题(每小题 1 分,共 10 分 , 对不正确的要写出理由) 1. 子模式 DDL 是用来描述数据库的物理存储结构的。(F ) 2. 同一个关系模型的任两个元组值不能全同。 (T ) 3. 基本表是本身独立存在的表,在 SQL 中一个关系就对应基本表。(T ) 4. 数据流程图( DFD )是用于描述结构化方法中详细设计阶段的工具。(F ) 5. 若数据库中只包含成功事务提交的结果则此数据库成为处于安全状态 (T ) 6. 事务的持续性是指事务中包括的所有操作,要么都做,要么都不做。 (F ) 7. DB 用户的权限可分为具有 DBA 特权的用户和一般 DB 用户(T ) 8. 数据库的网状模型应满足的条件是必须有两个以上的结点。(T ) 9. CREAT TABLE 命令可直接定义主码、外码、参照表,系统就能够自动地执行实体完整性和参照完整性规则。( T)

mysql数据库实验答案

实验一创建、修改数据库和表结构 1、用create建立教学数据库的五个基本表: (1)学生表(学号,姓名,性别,年龄),student((Sno, sname,ssex,sage) ; (2)课程表(课程号,课程名,学分),Course (Cno, Cname, credit) ; (3)选课表(学号,课程号,成绩),SC (Sno,, Cno, grade ) ; (4) 教师表(教师号,姓名,性别,出生年月,系部,职称,地址), T(Tno,Tname,ssex,birthday,dept,title,address) ; (5) 工资表(教师号,基本工资,职务工资,合计),Salary(Tno,jbgz,zwgz,hj); Create Database Student default character set utf8 default COLLATE utf8_bin;

Use Student; Create Table Student( SNo c har(20) primary key, SName char(20) , SSex char(4) default '男', SAge int ) ENGINE=InnoDB; Create Table Course( CNo c har(20) primary key, CName char(20) NOT NULL,

CRedit f loat ) ENGINE=InnoDB; Create Table SC( SNo c har(20) NOT NULL, CNo c har(20) NOT NULL, Grade float, Primary Key(SNo, CNo), Foreign Key(SNo) References Student(SNo) On Delete Cascade, Foreign Key(CNo) References Course(CNo) )ENGINE=InnoD B;

数据库基础知识试题(含答案)

数据库基础知识试题 部门____________ 姓名__________ 日期_________ 得分__________ 一、不定项选择题(每题1.5分,共30分) 1.DELETE语句用来删除表中的数据,一次可以删除( )。D A .一行 B.多行 C.一行和多行 D.多行 2.数据库文件中主数据文件扩展名和次数据库文件扩展名分别为( )。C A. .mdf .ldf B. .ldf .mdf C. .mdf .ndf D. .ndf .mdf 3.视图是从一个或多个表中或视图中导出的()。A A 表 B 查询 C 报表 D 数据 4.下列运算符中表示任意字符的是( )。B A. * B. % C. LIKE D._ 5.()是SQL Server中最重要的管理工具。A A.企业管理器 B.查询分析器 C.服务管理器 D.事件探察器 6.()不是用来查询、添加、修改和删除数据库中数据的语句。D A、SELECT B、INSERT C、UPDATE D、DROP 7.在oracle中下列哪个表名是不允许的()。D A、abc$ B、abc C、abc_ D、_abc 8.使用SQL命令将教师表teacher中工资salary字段的值增加500,应该使用的命令是 ()。D A、Replace salary with salary+500 B、Update teacher salary with salary+500 C、Update set salary with salary+500 D、Update teacher set salary=salary+500 9.表的两种相关约束是()。C

数据库应用试卷及答案

数据库及应用(B卷) 一、选择题(从备选答案中选1 个正确的答案,每题2分、共24分) 1.支持所有用户建立、存储数据库的软件系统是。 A.数据库系统 B.数据库管理系统 C.应用程序 D.操作系统2.DB的三级模式结构中最接近外部存储器的是。 A.子模式 B.外模式 C.概念模式 D.内模式 3.在关系模式R中,函数依赖X→Y的语义是。 A.在R的某一关系中,若两个元组的X值相等,则Y值也相等 B.在R的每一关系中,若两个元组的X值相等,则Y值也相等 C.在R的某一关系中,Y值应与X值相等 D.在R的每一关系中,Y值应与X值相等 4. DBA是________的简称。 A.系统分析员 B.应用程序员 C.数据库管理员 D.数据录入员 5. _____是长期存储在计算机内的有组织,可共享的数据集合. A.数据库管理系统B.数据库系统 C.数据库D.文件组织6.数据库系统的核心是。 A. 数据库 B. 数据库管理系统 C. 数据模型 D. 软件工具 7.客观存在并可相互区别的事物叫________。 A.码 B.属性 C.实体 D. 实体集8.数据库的完整性是指数据的_____和_____。 (1)正确性(2)合法性(3)不被非法存取 (4)相容性 (5)不被恶意破坏 A. (1)和(3) B. (2)和(5) C. (1)和(4) D. (2)和(4) 9.一组具有相同数据类型的值的集合称为________。 A.关系 B.属性 C.分量 D.域 10.以下______封锁违反两段锁协议。 A.Slock A … Slock B … Xlock C …… Unlock A … Unlock B … Unlock C B.Slock A … Slock B … Xlock C …… Unlock C … Unlock B … Unlock A C.Slock A … Slock B … Xlock C …… Unlock B … Unlock C … Unlock A D.Sl ock A …Unlock A …Slock B … Xlock C …… Unlock B … Unlock C 11. “日志”文件用于保存________。 A.程序运行过程B.数据操作 C.程序执行结果D.对数据库的更新操作12…并发操作会带来哪些数据不一致性________ A.丢失修改、不可重复读、读脏数据、死锁 B.不可重复读、读脏数据、死锁

相关主题