Vous êtes sur la page 1sur 13

Answers to Review Questions

1. What is the difference between a database and a table? A table, a logical structure that represents an entity set, is only one of the components of a database. The database is a structure that houses one or more tables and metadata. The metadata are data about data. Metadata include the data (attribute) characteristics and the relationships between the entity sets. 2. What does a database expert mean when (s)he observes that a database displa s both entit inte!rit and referential inte!rit ? Entity integrity describes a condition in which all tuples within a table are uniquely identified by their primary key. The unique value requirement prohibits a null primary key value, because nulls are not unique. Referential integrity describes a condition in which a foreign key value has a match in the corresponding table or in which the foreign key value is null. The null foreign key value makes it possible not to have a corresponding value, but the matching requirement on values that are not null makes it impossible to have an invalid value. ". Wh are entit inte!rit and referential inte!rit important in a database? ntity integrity is important, because it means that a proper search for an existing tuple (row) will always be successful. And the failure to find a match on a row search will always mean that the row for which the search is conducted does not e!ist in that table. "eferential integrity is important, because its e!istence ensures that it will be impossible to assign a non#e!isting foreign key value to a table. $or e!ample, the referential integrity enforcement in a %A& %" ' is assigned to ()%T*M " relationship means that it will be possible for a customer not have a sales rep assigned to him or her, but it will be impossible to assign non#e!isting sales rep to a customer. #. A database manual notes that $the file contains two hundred records% each one of which contains nine fields.$ &se appropriate relational database terminolo! to $translate$ the precedin! statement. )sing the proper relational terminology, the statement may be translated to +the table ## or entity set ## contains two hundred rows ## or, if you like, two hundred tuples, or entities. ach of these rows contains nine attributes.+

'. &se the small database shown in (i!ure Q2.' to illustrate the difference between a natural )*+,% an e-ui)*+,% and an outer)*+,.

(i!ure Q2.' .he /atabase for Questions ' 0 1


/atabase name2 3425Q&67.+*,7 .able name 7.&/6,. .able name2 8R*(677*R

(,ote- These database tables are found in the (./01) %T2*,% database on the 2nstructor3s (4.) The natural 5*2, process begins with the '"*4)(T of the two tables7.&53*/6 8R*(53*/6

8R*(5 3* /6
6 6 6 6 6 6 / / / / / / > > > > > > = = = = = =

/68.53*/6

677/89 6/9:;< :6//8/ :>6/>: :>6/;9 ::>=/8 677/89 6/9:;< :6//8/ :>6/>: :>6/;9 ::>=/8 677/89 6/9:;< :6//8/ :>6/>: :>6/;9 ::>=/8 677/89 6/9:;< :6//8/ :>6/>: :>6/;9 ::>=/8

/ = / 6 / = / 6 / = / 6 / = / 6

/ / / / / / ; ; ; ; ; ; ; ; ; ; ; ; = = = = = =

,e!t, a % & (T is performed on the '"*4)(T generated in the first step to yield only the rows for which the '"*$0(*4 values in the %T)4 ,T table are matched in the '"*$ table. ?ecause only the %T)4 ,T table3s '"*$0(*4 values 6, /, and = yield matches in the '"*$ %%*" table, the % & (T yields the following output7.&53*/6 8R*(53*/6

8R*(5 3* /6
/ = / 6

/68.53*/6

6/9:;< :6//8/ :>6/>: ::>=/8

/ = / 6

; = ; /

$inally, a '"*5 (T is performed to produce the natural 5*2, output by listing only a single copy of each attribute. The order in which the query output rows are shown is not relevant. 2f the output is to be listed by having the %T)0(*4 values in ascending order, this result can be generated through an @order byA specification in the query B remind the students that they can learn how that is done in (hapter :, @%tructured 1uery &anguage (%1&)A.
7.&53*/6 6/9:;< :6//8/ :>6/>: ::>=/8 8R*(53*/6 / = / 6 /68.53*/6 ; = ; /

The equi5*2,Cs results depend on the specified condition. $or instance, if the equi5*2, specifies that A&& %T)4 ,T% $*" D.*M T. A4E2%*" (*4 2% / are to be listed, the output will be
7.&53*/6 6/9:;< :>6/>: 8R*(53*/6 / / /68.53*/6 ; ;

2n the outer5*2,, the unmatched pairs would be retained and the values that do not have a match in the other table would be left null. Therefore, the will yield these results7.&53*/6 677/89 6/9:;< :6//8/ :>6/>: :>6/;9 ::>=/8 8R*(53*/6 / = / 6 > /68.53*/6 ; = ; / ;

Microsoft Access uses two outer Foin options to make it easy to find unmatched pairs. $or e!ample, its outer Foin selections, generated from its 1? (1uery ?y !ample) query generator, are particularly effective. ,ote, for e!ample, the selected left outer Foin option in $igure 1/.:A6 and look at its output in $igure 1/.:A/ to see that professor > does not have any student advisees.

(i!ure Q2.'A1 .he 9eft *uter )oin Q:6 properties selection

2f you select the option / in $igure 1/.:A63s 1? option screen, you3d get the output shown in $igure 1/.:A/. ,ote that you can now easily detect that professor number > does not have any student advisees assigned to him or her. 2f you select the option > in $igure 1/.:A63s 1? option screen, you3d get the output shown in $igure 1/.:A>. The latter output makes it easy to detect that students 677/89 and :>6/;9 do not yet have an advisor assigned to them.

(i!ure Q2.'A2 (i!ure Q2.'A1;s 9eft *uter )oin *utput (i!ure Q2.'A" .he Ri!ht *uter )oin *utput

<. /raw the basic 6ntit Relationship dia!ram for the database shown in (i!ure Q2.'. The (hen and (row3s $oot #" diagrams are shown ne!tThe (hen "4
1 8 R* ( 677*R advi s es ? 7.&/ 6,.

The (row3s $oot "4

8R * (67 7 *R

ad v i s es

7 .& / 6, .

1. /raw the relational schema for the database shown in (i!ure Q2.'. The relational schema is shown ne!t-

=. 7uppose that ou have the 6ntit Relationship model shown in (i!ure Q2.=2

(+>&R6 Q2.= .he 6R/ (or Question =

/R+A6R

drives

.R&3B

/urin! some time interval% a /R+A6R can drive m an a nd a n .R&3B can be driven b man /R+A6Rs

different .R&3Bs

4ow would ou convert this model into an 6ntit Relationship model that displa s onl 12? relationships? (?a@e sure that ou draw the revised entit relationship model.) ?ecause the relational database model does not support the M-, relationship between entities, we must convert the M-, relationship into a set of 6-M relationships that are linked through a composite or bridge entity. The name composite entity is based on the fact that the linking table contains at least the primary keys of each of the tables that it connects.
1 / R+A 6R ? A77 + >, ?6, . ? 1 .R & 3 B

The (hen model will look like this-

The (row3s $oot model yields this solution to question 9/ R +A 6R g et s A 77+>, ?6 , . is d r iv en in .R & 3B

C. What are homon ms and s non ms% and wh should the !enerall be avoided in database desi!n? .omonyms appear when more than one attribute has the same name. %ynonyms e!ist when the same attribute has more than one name. Avoid both to avoid inconsistencies. $or e!ample, suppose we check the database for a specific attribute such as ,AM . 2f ,AM refers to customer names as well as to sales rep names, a clear case of a homonym, we have created a problem, because it is no longer clear which entity the ,AM belongs to. Also, it is difficult to keep track of foreign keys, especially during the database design process, if they are named differently from the primary keys they point to. )sing " '0,)M as the foreign key in the ()%T*M " table to reference the primary key " '0,)M in the %A& %" ' table is much clearer than naming the ()%T*M " tableCs foreign key %&%" '. The proliferation of different attribute names to describe the same attributes will also make the data dictionary more cumbersome to use. %ome data "4?M%es let the data dictionary check for homonyms and synonyms to alert the user to their e!istence, thus making their use less likely. $or e!ample, if a ()%T*M " table contains the (foreign) key " '0,)M, the entry of the attribute " '0,)M in the %A& %" ' table will either cause it to inherit all the characteristics of the original " '0,)M, or it will reFect the use of this attribute name when different characteristics are declared by the user.

,ote2 9i@e most rules% the homon mDs non m avoidance rule is sometimes bro@en to fit a perceived need. +n fact% we have seen (too man ) applications in which a table must emplo two forei!n @e s to reference one attribute in another table. (or example% an aircraft charter compan ma schedule a fli!ht crew of two pilots to fl an airplane% one to fl as pilot in command and one as copilot. An of the compan Es pilots ma be scheduled either as pilot in command or as copilot. .herefore% the 7346/&96 entit mi!ht be implemented to re-uire both 8+9*. and 3*8+9*. attributes. Fet the 8+9*. table contains onl one row for each pilotEs attributes% so the 7346/&96 entit must use two forei!n @e s to access the same 8+9*. entit . (We have used this approach in problems 2C0"1 3425AA+A53* aviation database as an illustration.) While this solution wor@s% it is unnecessar and% worse% it limits the crew assi!nments. (or example% what happens when a crew is composed of more than Gust a pilot and copilot? 7hould we then add a third H or a fourth% a fifth% and so on 00 s non m in the 7346/&96 table? A much better solution H one that avoids s non ms 00 would not re-uire structural chan!es to accommodate chan!in! crew re-uirements. 7uch a solution would use a composite entit to lin@ the crew and the airplane to the assi!nment schedule. Althou!h we will revisit this critical desi!n issue in 3hapter "% it is not too earl to introduce this example as the proverbial e e opener. 1I. 4ow would ou implement a 12? relationship in a database composed of two tables? >ive an example. %uppose that we have a car entity and an owner entity. $urther suppose that it is reasonable to assume that a car is owned Fust by one person (owner) a person can own more than one car. The relationships we have Fust described may be represented by the following #" model1 3 & 7 .*? 6R ow ns ? 3AR

(hen model (row3s $oot model

3 &7.* ?6 R

owns

3AR

An e!ample of this relationship is shown ne!t. ,ote that the +many+ side of the relation (the (A" entity) contains the foreign key, which is the ()%T*M " entityCs primary key.

.able name2 3&7.*?6R

.able name2 3AR

(i!ure Q2.1I Question 1IEs Relational 7chema

11. +dentif and describe the components of the database table shown in (i!ure Q2.11% usin! correct terminolo! . &se our @nowled!e of the namin! conventions to identif the tableEs probable forei!n @e (s).

(+>&R6 Q2.11 .he 6?89*F66 .able for Question 11


Table name- M'&*G /atabase name2 3425Q&67.+*,7

$igure 1/.66Cs database table contains-

one entit set2 M'&*G

. M'0&,AM , M'02,2T, M'0$,AM ,

five attributes2 M'0,)M, 4 'T0(*4 and 5*?0(*4 .

ten entities2 the workers $riedman, *lansky, $ontein, and (ruaHona. @e 2 the attribute M'0,)M because it identifies each row

one primar uniquely.

two forei!n @e s2 the attribute 4 'T0(*4 , which probably references a department to which the employee is assigned and the attribute 5*?0(*4 which probably references another table in which you would find the description of the Fob and perhaps additional information pertaining to the Fob.

12. 7uppose that ou are usin! the followin! a database composed of the two tables shown in (i!ure Q2.122

(i!ure Q2.12 .he /atabase (or Question 12


Table name- 42" (T*" /atabase name2 3425Q&67.+*,7

Table name- '&AG

a. +dentif the primar @e s. 42"0,)M is the 42" (T*" tableCs primary key. '&AG0(*4 is the '&AG tableCs primary key. b. +dentif the forei!n @e . The foreign key is 42"0,)M, located in the '&AG table. ,ote that the foreign key is located on the +many+ side of the relationship between director and play. ( ach director can direct many plays ... but each play is directed by only one director.) c. /raw the 6ntit Relationship model.
1 ? d i re cts 89A F

(hen model (row3s $oot model

/+R 63 .*R

/ + R63. * R

direct s

8 9 AF

d. /raw the relational schema to show the relationship between /+R63.*R and 89AF.

e. 7uppose ou wanted -uic@ loo@up capabilit to !et a listin! of all the pla s directed b a !iven director. What table would be the basis for the index table% and what would be the index @e ? The '&AG table would be the basis for the appropriate inde! table. The inde! key would be the attribute 42"0,)M. f. What would be the conceptual view of the index table described in part e? /epict the contents of the (conceptual) index table. /+R5,&? 677 676 67/ +ndex @e (pointers to the 89AF table) = /, :, 8 6, >, ;

ach 42"0,)M entry in the inde! file contains an ordered sequence of record numbers pointing to the corresponding rows in the '&AG table. $or e!ample, the director number +677+ has only one play to match row = in the '&AG table. Note that the number 4 represents the fourth record in the PLAY table, not the play whose primary key is 4 .

Vous aimerez peut-être aussi