Finalexam Ws2011 2012 Databases

16
P a g e  0 G e r m a n U n i v e r s i t y i n C a i r o  J a n u a r y 1 1 , 2 0 1 2  F a c u l t y o f M e d i a E n g i n e e r i n g a n d T e c h n o l o g y  P r o f . D r . S l i m A b d e n n a d h e r  F i n a l E x a m  B a r C o d e  I n s t r u c t i o n s : R e a d c a r e f u l l y b e f o r e p r o c e e d i n g .  1 ) P l e a s e t i c k y o u r m a j o r  M a j o r  C S E N  D M E T  B I 2 ) D u r a t i o n o f t h e e x a m : 3 h o u r s ( 1 8 0 m i n u t e s ) .  3 ) ( N o n - p r o g r a m m a b l e ) C a l c u l a t o r s a r e a l l o w e d .  4 ) N o b o o k s o r o t h e r a i d s a r e p e r m i t t e d f o r t h i s t e s t .  5 ) T h i s e x a m b o o k l e t c o n t a i n s 1 5 p a g e s , i n c l u d i n g t h i s o n e . T h r e e e x t r a s h e e t s o f s c r a t c h p a p e r a r e  a t t a c h e d a n d h a v e t o b e k e p t a t t a c h e d .  N o t e t h a t i f o n e o r m o r e p a g e s a r e m i s s i n g , y o u w i l l  l o s e t h e i r p o i n t s . T h u s , y o u m u s t c h e c k t h a t y o u r e x a m b o o k l e t i s c o m p l e t e  . 6 ) W r i t e y o u r s o l u t i o n s i n t h e s p a c e p r o v i d e d . I f y o u n e e d m o r e s p a c e , w r i t e o n t h e b a c k o f t h e s h e e t  c o n t a i n i n g t h e p r o b l e m o r o n t h e t h r e e e x t r a s h e e t s a n d m a k e a n a r r o w i n d i c a t i n g t h a t .  S c r a t c h  s h e e t s w i l l n o t b e g r a d e d u n l e s s a n a r r o w o n t h e p r o b l e m p a g e i n d i c a t e s t h a t t h e  s o l u t i o n e x t e n d s t o t h e s c r a t c h s h e e t s  . 7 ) W h e n y o u a r e t o l d t h a t t i m e i s u p , s t o p w o r k i n g o n t h e t e s t .  G o o d L u c k !  D o n ' t w r i t e a n y t h i n g b e l o w  ; - ) E x e r c i s e 1 2 3 4 5 6 7 8   M a r k s 8 1 2 1 2 6 8 1 3 8 5 7 2  F i n a l M a r k s  

Transcript of Finalexam Ws2011 2012 Databases

Page 1: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 1/16

P a g e   0 

G e r m a n U n i v e r s i t y i n C a i r o   J a n u a r y 1 1 , 2 0 1 2  

F a c u l t y o f M e d i a E n g i n e e r i n g a n d T e c h n o l o g y  

P r o f . D r . S l i m A b d e n n a d h e r  

D a t a b a s e s I    

S p r i n g t e r m 2 0 1 1      

F i n a l E x a m  

B a r C o d e  

I n s t r u c t i o n s : R e a d c a r e f u l l y b e f o r e p r o c e e d i n g .  

1 ) P l e a s e t i c k y o u r m a j o r  

M a j o r  

C S E N  

D M E T  

B I 

2 ) D u r a t i o n o f t h e e x a m : 3 h o u r s ( 1 8 0 m i n u t e s ) .  

3 ) ( N o n - p r o g r a m m a b l e ) C a l c u l a t o r s a r e a l l o w e d .  

4 ) N o b o o k s o r o t h e r a i d s a r e p e r m i t t e d f o r t h i s t e s t .  

5 ) T h i s e x a m b o o k l e t c o n t a i n s 1 5 p a g e s , i n c l u d i n g t h i s o n e . T h r e e e x t r a s h e e t s o f s c r a t c h p a p e r a r e  

a t t a c h e d a n d h a v e t o b e k e p t a t t a c h e d .   N o t e t h a t i f o n e o r m o r e p a g e s a r e m i s s i n g , y o u w i l l  

l o s e t h e i r p o i n t s . T h u s , y o u m u s t c h e c k t h a t y o u r e x a m b o o k l e t i s c o m p l e t e  . 

6 ) W r i t e y o u r s o l u t i o n s i n t h e s p a c e p r o v i d e d . I f y o u n e e d m o r e s p a c e , w r i t e o n t h e b a c k o f t h e s h e e t  

c o n t a i n i n g t h e p r o b l e m o r o n t h e t h r e e e x t r a s h e e t s a n d m a k e a n a r r o w i n d i c a t i n g t h a t .   S c r a t c h  

s h e e t s w i l l n o t b e g r a d e d u n l e s s a n a r r o w o n t h e p r o b l e m p a g e i n d i c a t e s t h a t t h e  

s o l u t i o n e x t e n d s t o t h e s c r a t c h s h e e t s  . 

7 ) W h e n y o u a r e t o l d t h a t t i m e i s u p , s t o p w o r k i n g o n t h e t e s t .  

G o o d L u c k !  

D o n ' t w r i t e a n y t h i n g b e l o w   ; - ) 

E x e r c i s e 1 2 3 4 5 6 7 8  

M a r k s 8 1 2 1 2 6 8 1 3 8 5 7 2  

F i n a l M a r k s  

Page 2: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 2/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  1 

E x e r c i s e 1   ( 2 + 6 = 8 M a r k s )  

a ) W h e n i s t h e f o l l o w i n g r e l a t i o n a l a l g e b r a e x p r e s s i o n s e q u i v a l e n t . J u s t i f y y o u r a n s w e r :  

πX(σC (S )) = σC (πX(S ))

S o l u t i o n :  

I f t h e c o n d i t i o n   C  u s e s o n l y a t t r i b u t e s f r o m t h e s e t o f a t t r i b u t e s  X 

b ) C o n s i d e r t w o r e l a t i o n s a b o u t r e s t a u r a n t s a n d m e a l s t h e y s e r v e :  

r e s t a u r a n t ( r n a m e , c u i s i n e , z i p )  

w h e r e t h e   r n a m e   i s t h e p r i m a r y k e y .  

E x a m p l e s o f r e c o r d s i n t h e   r e s t a u r a n t   t a b l e  

r n a m e c u i s i n e z i p  

B a n g k o k T h a i 9 7 2 0 1  

C h u r r a ' s B r a z i l i a n 9 7 2 0 3  

O s k a r ' s G e r m a n 9 7 2 2 5  

. . . . . . . . .  

o p e n ( r n a m e , m e a l )  

w h e r e   r n a m e , m e a l   i s t h e p r i m a r y k e y .  

E x a m p l e o f r e c o r d s i n t h e   o p e n   t a b l e :  

r n a m e m e a l  

B a n g k o k l u n c h  

B a n g k o k d i n n e r  

C h u r r a ' s d i n n e r  

. . . . . .  

C o n s i d e r t h e f o l l o w i n g r e l a t i o n a l a l g e b r a q u e r y o v e r t h e s e t w o t a b l e s ( w h e r e r = r e s t a u r a n t a n d o  

= o p e n ) . G i v e t h r e e o t h e r a l g e b r a e x p r e s s i o n s t h a t a r e e q u i v a l e n t t o t h i s q u e r y . ( T h e e x p r e s s i o n s  

y o u g i v e s h o u l d b e e q u i v a l e n t f o r a n y s t a t e o f t h e d a t a b a s e . )  

πr.cuisine(σo.meal=dinner∧r.zip=97241(o 1o.rname=r.rname r))

S o l u t i o n :  

T h e r s t a l t e r n a t i v e :  

πr.cuisine(σr.zip=97241(σo.meal=dinner(o) 1o.rname=r.rname r))

T h e s e c o n d a l t e r n a t i v e :  

πr.cuisine(σo.meal=dinner(o 1o.rname=r.rname σr.zip=97241(r)))

T h e t h i r d a l t e r n a t i v e :  

πr.cuisine((σo.meal=dinner(o) 1o.rname=r.rname σr.zip=97241(r)))

Page 3: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 3/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  2 

T h e f o l l o w i n g t w o e x e r c i s e s a r e b a s e d o n t h e L i b r a r y d a t a b a s e , w h i c h c o n t a i n s s i x r e l a t i o n s :  

a ) P e r s o n s t o r e s t h e r s t n a m e , t h e m i d d l e i n i t i a l a n d l a s t n a m e o f L i b r a r y s ' h e a d m a n a g e r s , b o o k s '  

A u t h o r s , a n d S t u d e n t s a s w e l l a s t h e i r a d d r e s s , s e x , t e l e p h o n e n u m b e r a n d t h e s t u d e n t s ' m a t r i c u -  

l a t i o n n u m b e r ( i f t h e p e r s o n i s a s t u d e n t o t h e r w i s e N U L L v a l u e s w i l l b e p r o v i d e d ) .   I D P  i s a s e r i a l  

n u m b e r .  

P e r s o n ( F N A M E , M I N I T , L N A M E , I D P , A D D R E S S , S E X , M A T , D A T E B I R T H , P H O N E )  

b ) A u t h o r s t o r e s t h e c o r r e s p o n d e n c e a m o n g B o o k s a n d t h e p e o p l e w h o w r o t e t h e m .  

A u t h o r ( I S B N , I D P )  

c ) B o o k s t o r e s t h e I S B N o f e a c h b o o k o f t h e l i b r a r y , i t s t i t l e , a n d i t s p u b l i s h i n g d a t e .  

B o o k ( T i t l e , I S B N , P D a t e )  

d ) C o p y s t o r e s i n w h i c h l i b r a r y i s e v e r y s i n g l e c o p y o f e a c h b o o k l o c a t e d w h e r e   I D C  i s a s e r i a l n u m b e r  

f o r d i e r e n t c o p i e s o f b o o k s a n d   I D L  i s t h e I D f o r t h e l i b r a r y .  

C o p y ( I D C , I S B N , I D L )  

e ) B o r r o w e r s t o r e s t h e m a t r i c u l a t i o n n u m b e r o f t h e s t u d e n t h a v i n g c u r r e n t l y b o r r o w e d a b o o k a n d  

t h e d a t e w h e n h e o r s h e b o r r o w e d i t . T h e t a b l e a l s o c o n t a i n t h e r e s e r v a t i o n ' s e x p i r i n g d a t e a n d a  

b o o l e a n e l d ( R e t u r n e d ) i n d i c a t i n g i f t h e b o o k h a s b e e n g i v e n b a c k o r n o t .   I D B  i s a s e r i a l n u m b e r  

f o r B o r r o w e r .  

B o r r o w e r ( I D B , I D C , M A T , R e n t i n g D a t e , E x p e r i n g D a t e , R e t u r n e d )  

f ) L i b r a r y s t o r e s a n u m b e r i d e n t i f y i n g e a c h l i b r a r y , i t s n a m e , i t s a d d r e s s a n d n a l l y t h e I D o f i t s  

m a n a g e r .  

L i b r a r y ( L N a m e , I D L , I D M g r , M g r S t a r t D a t e )  

Page 4: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 4/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  3 

E x e r c i s e 2   ( 1 2 M a r k s )  

F o r m u l a t e r e l a t i o n a l a l g e b r a e x p r e s s i o n s t h a t a n s w e r t h e f o l l o w i n g q u e r i e s .  

a ) A l l t i t l e s o f b o o k s b o r r o w e d b y t h e s t u d e n t ' C e c i l i a B a r t o l i ' .  

S o l u t i o n :  

πTITLE(Book 1Book.ISBN =Copy.ISBN  Copy 1Copy.IDC =Borrowe.IDC  Borrower

1Borrower.MAT =Person.MAT  (σFNAME=Cecilia∧LNAME=Baroli (Person)))

b ) T h e f u l l n a m e s o f a l l l i b r a r y m a n a g e r s a n d t h e n a m e o f t h e l i b r a r y t h e y a r e m a n a g i n g .  

S o l u t i o n :  

πPerson.FNAME,P erson.MINIT ,Person.LNAME,Library.LNAME(Person 1Person.IDP =Library.IDMgr Library)

c ) T h e m a t r i c u l a t i o n n u m b e r a n d t h e f u l l n a m e o f t h e s t u d e n t s h a v i n g n o b o o k b o r r o w e d .  

S o l u t i o n :  

πMAT,FNAME,MINIT,LNAME (Person) −

πMAT,FNAME,MINIT,LNAME (Person 1Person.MAT =Borrwer.MAT  Borrower)

d ) T h e I S B N a n d t h e t i t l e o f b o o k s t h a t a r e c u r r e n t l y a v a i l a b l e t h r o u g h t h e l i b r a r y .  

S o l u t i o n :  

πBook.ISBN,Book.TITLE((πIDC (Copy) − πIDC (Borrower)) 1 Copy 1 Book) ( 1 ) 

e ) T h e n a m e a n d t h e s u r n a m e o f e a c h m a n a g e r , t o g e t h e r w i t h t h e n a m e , s u r n a m e a n d p h o n e n u m b e r  

o f t h e s t u d e n t s h a v i n g b o r r o w e d i n h e r / h i s l i b r a r y a b o o k b e f o r e J a n u a r y 1 , 2 0 1 1 w i t h o u t r e t u r n i n g  

i t . 

S o l u t i o n :  

Person 1Borrower.MAT =Person.MAT 

πLibrary.IDMgr,Borrower.MAT (σBorrower.returned=false∧Borrower.Rentingdate<1/1/2011(Borrower

1Copy.IDC =Borrower.IDC Copy 1Copy.IDL=Lib.IDL

(ρLib(IDL,IDMgr,MgrFname,MgrLname)(πLibrary.IDL,Library.IDMgr,Person.FNAME,Person.LNAME

(Person 1Library.IDMgr=Person.IDP  Library)))))

Page 5: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 5/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  4 

E x e r c i s e 3   ( 1 2 M a r k s )  

F o r m u l a t e S Q L q u e r i e s t h a t s o l v e t h e t a s k s l i s t e d b e l o w .  

a ) A l l t h e d a t a o f t h e f e m a l e s t u d e n t s h a v i n g n e v e r b o r r o w e d a b o o k  

S o l u t i o n :  

S E L E C T *  

F R O M P e r s o n  

L E F T O U T E R J O I N B o r r o w e d  

O N P e r s o n . M A T = B o r r o w e d . M A T  

W H E R E P e r s o n . S E X = ' f e m a l e ' A N D B o r r o w e d . M A T I S N U L L  

b ) T h e f u l l n a m e o f t h e s t u d e n t s b e i n g c o - a u t h o r o f a t l e a s t o n e B o o k . C o a u t h o r : a w r i t e r w h o c o l l a -  

b o r a t e s w i t h o t h e r s i n w r i t i n g s o m e t h i n g . T h a t i s a p e r s o n w h o w r o t e a b o o k n o t a l o n e .  

S o l u t i o n :  

S E L E C T P e r s o n . F N A M E , P e r s o n . M I N I T , P e r s o n . L N A M E  

F R O M P e r s o n  

I N N E R J O I N A u t h o r A 1  

O N P e r s o n . I D P = A 1 . I D P  

W H E R E P e r s o n . M D P I S N O T N U L L  

A N D E X I S T S ( S E L E C T *  

F R O M A u t h o r A 2  

W H E R E A 1 . I S B N = A 2 . I S B N A N D A 1 . I D P < > A 2 . I D P )  

c ) T h e n a m e a n d t h e I S B N o f t h e b o o k s f o r w h i c h a t l e a s t 2 c o p i e s a r e a v a i l a b l e f o r r e n t  

S o l u t i o n :  

S E L E C T B . I S B N , B . T i t l e  

F r o m B o o k B  

W H E R E 2 < = ( ( S E L E C T C O U N T ( * )  

F R O M C o p y C  

W H E R E B . I S B N = C . I S B N )  

( S E L E C T C O U N T ( * )  

F R O M C o p y C , B o r r o w e r B o  

W H E R E C . I S B N = B o . I S B N  

A N D B . I S B N = C . I S B N  

A N D r e t u r n e d = f a l s e ) )  

d ) T h e f u l l n a m e o f t h e a u t h o r s h a v i n g t h e i r f u l l n a m e l o n g e r t h a n 1 5 c h a r a c t e r s a n d h a v i n g a s u r n a m e  

t h a t i n c l u d e s t h e s t r i n g   ' o v '   . 

S o l u t i o n :  

S E L E C T P e r s o n . F N A M E , P e r s o n . L N A M E  

F R O M P e r s o n P  

I N N E R J O I N A u t h o r A  

O N P . I D P = A . I D P  

W H E R E P . L N A M E L I K E ' % a v % '  

A N D L E N G T H ( F N A M E ) + L E N G T H ( M I N I T ) + L E N G T H ( L N A M E ) > 1 5  

e ) T h e a v e r a g e n u m b e r o f b o o k s ( c o p i e s ) r e n t e d n o w a n d i n t h e p a s t b y t h e m a l e s t u d e n t s b e i n g o l d e r  

t h a n t h e a v e r a g e m a l e s t u d e n t . ( M a y b e y o u c a n u s e a v i e w . ) . B e s u r e t o c o u n t a l s o a s 0 t h e s t u d e n t s  

h a v i n g n e v e r b o r r o w e d a b o o k .  

S o l u t i o n :  

Page 6: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 6/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  5 

C R E A T E V I E W P V ( P , C ) A S  

S E L E C T P . M A T , 0  

F R O M P e r s o n P  

L E F T O U T E R J O I N B o r r o w e r B  

O N P . M A T = B . M A T  

W H E R E P . S E X = m a l e A N D B . M A T I S N U L L  

U N I O N  

S E L E C T P . M A T , S U M ( B . I D C )  

F R O M P e r s o n P  

I N N E R J O I N B o r r o w e r B  

O N P . M A T = B . M A T  

W H E R E P . S E X = m a l e  

G R O U P B Y P . M A T  

G O 

S E L E C T A V G ( C )  

F R O M P e r s o n P  

I N N E R J O I N P V  

O n P V . P = P . M A T  

W H E R E A V G ( C U R R E N T _ D A T E - P . D A T E B I R T H ) >  

( S E L E C T A V G ( C U R R E N T _ D A T E - P 2 . D A T E B I R T H )  

F R O M P e r s o n P 2  

W H E R E P 2 . S E X = ' M a l e ' A N D P 2 . M A T I S N O T N U L L )  

Page 7: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 7/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  6 

T h e f o l l o w i n g t w o e x e r c i s e s a r e b a s e d o n t h e f o l l o w i n g   C a r  d a t a b a s e .  

T h e c a r d e a l e r O m a r w o u l d l i k e t o o r g a n i z e h i s i n v e n t o r y i n a r e l a t i o n a l d a t a b a s e s y s t e m . T h e r e q u i r e -  

m e n t s a n a l y s i s l e d t o s t o r e i n f o r m a t i o n a b o u t e a c h c a r t h a t O m a r c o n v e r t e d i n t o a r e l a t i o n a l s c h e m a .  

I m m e d i a t e l y , h e b e g i n s w i t h t h e c o l l e c t i o n o f h i s o l d d a t a a n d o b t a i n e d t h e f o l l o w i n g r e l a t i o n   C a r  : 

m o d N r m a n N r m a n u f t y p e p o w e r v e h i c l e N r y e a r O f C m i l e a g e n e w P s a l e P p u r c h a s e P  

1 1 O p e l K a d e t t 6 0 K 6 7 4 1 9 9 0 1 0 0 0 0 1 8 0 0 0 1 3 0 0 0 1 2 0 0 0  

1 1 O p e l K a d e t t 6 0 K 6 3 4 1 9 8 8 3 4 0 0 0 1 8 0 0 0 1 2 0 0 0 9 0 0 0  

2 1 O p e l V e c t r a 9 0 V 4 5 9 1 9 9 0 1 5 0 0 0 2 5 0 0 0 1 8 0 0 0 1 7 0 0 0  

3 1 O p e l O m e g a 1 1 0 O 6 3 4 1 9 8 7 4 5 0 0 0 3 0 0 0 0 2 2 0 0 0 1 5 0 0 0  

4 2 V W G o l f 9 0 G 7 8 9 1 9 9 1 1 1 0 0 0 2 5 0 0 0 2 1 0 0 0 1 6 0 0 0  

4 2 V W G o l f 9 0 G 7 1 3 1 9 9 1 3 1 0 0 0 2 5 0 0 0 1 6 0 0 0 1 3 0 0 0  

5 2 V W G o l f 1 0 5 G 7 6 2 1 9 9 2 2 8 0 0 0 2 8 0 0 0 1 9 0 0 0 1 7 0 0 0  

6 2 V W B e a t l e s 6 0 K 6 3 4 1 9 8 6 7 1 0 0 0 1 9 0 0 0 1 0 0 0 0 8 0 0 0  

T h e d i e r e n t c a r m o d e l s a r e s e r i a l l y n u m b e r e d ( m o d N r ) . A m o d e l i s d e n e d w i t h t h e m a n u f a c t u r e r  

( m a n u f ) , t h e m a n u f a c t u r e r n u m b e r ( m a n N r ) , t y p e a n d e n g i n e p o w e r ( p o w e r ) . F o r e a c h m o d e l , t h e v e h i c l e  

n u m b e r ( v e h i c l e N r ) i s u n i q u e . B o t h a t t r i b u t e s ( m o d N r , v e h i c l e N r ) w i l l b e s e l e c t e d a s t h e p r i m a r y k e y .  

A f t e r a w h i l e , O m a r n o t i c e d t h a t h e d o e s n o t e n j o y h i s d a t a b a s e s a n y m o r e . T h e d a t a m o d e l i n g s e e m s n o t  

t o b e w e l l t h o u g h t .  

Page 8: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 8/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  7 

E x e r c i s e 4   ( 6 M a r k s )  

D e s c r i b e t h e p r o b l e m s ( r e d u n d a n c y a n d a n o m a l i e s ) t h a t c o u l d o c c u r i f y o u u s e t h e a b o v e r e l a t i o n a l  

s c h e m a .  

S o l u t i o n :  

• I n s e r t i o n A n o m a l y : A n i n s e r t i o n a n o m a l y w i l l o c c u r w h e n e v e r t h e u s e r a t t e m p t s t o i n s e r t a n e w  

m o d e l f o r w h i c h n o v e h i c l e s a r e p r o d u c e d .  

• U p d a t e A n o m a l y : W h e n a m a n u f a c t u r e r ' s d a t a i s u p d a t e d , i t m a y o c c u r t h a t i t s i n f o r m a t i o n ( T h e  

m o d N r ) w i l l n o t b e u p d a t e d f o r a l l t u p l e s .  

• D e l e t i o n A n o m a l y : I f a l l c a r s o f a s p e c i c m o d e l ( o r m a n u f a t u r e r ) a r e d e l e t e d , a l l i n f o r m a t i o n a b o u t  

t h e m o d e l ( o r t h e m a n u f a c t u r e r ) w i l l b e d e l e t e d .  

Page 9: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 9/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  8 

E x e r c i s e 5   ( 2 + 4 + 2 = 8 M a r k s )  

A s s u m e y o u h a v e t h e f o l l o w i n g n o n - t r i v i a l f u n c t i o n a l d e p e n d e n c i e s :  

m o d N r   → m a n N r , m a n u f , t y p e , p o w e r  

v e h i c l e N r   → m a n u f  

m o d N r , v e h i c l e N r   → y e a r O f C , m i l e a g e , n e w P , s a l e P , p u r c h a s e P  

a ) E x p l a i n w h y t h e r e l a t i o n a l s c h e m a i s n o t i n s e c o n d n o r m a l f o r m .  

S o l u t i o n :  

b ) T h e r s t a n d s e c o n d f u n c t i o n a l d e p e n d e n c i e s v i o l a t e s t h e s e c o n d n o r m a l f o r m a s t h e i r r i g h t - h a n d -  

s i d e s a r e d e p e n d a n t o n p a r t o f t h e k e y . I n t h e c a s e o f t h e r s t F D , t h e y a r e d e p e n d a n t o n t h e   m o d N r  . 

I n c a s e o f t h e s e c o n d o n e , t h e y a r e d e p e n d a n t o n t h e   v e h i c l e N r  

c ) T r a n s f o r m t h e r e l a t i o n a l s c h e m a i n t o s e c o n d n o r m a l f o r m .  

S o l u t i o n :  

R 1 ( m o d N r , m a n N r , m a n u f , t y p e , p o w e r )  

R 2 ( v e h i c l e N r , m a n u f )  

R 3 ( m o d N r , v e h i c l e N r , y e a r O f C , m i l e a g e , n e w P , s a l e P , p u r c h a s e P )  

- - - - - - - - - - -  

R 3 . m o d N r r e f e r e n c e s R 1  

R 3 . v e h i c l e N r r e f e r e n c e s R 2  

d ) I f t h e t r a n s f o r m e d r e l a t i o n a l s c h e m a i s n o t i n t h i r d n o r m a l f o r m , t r a n s f o r m i t i n t o t h i r d n o r m a l f o r m .  

O t h e r w i s e j u s t i f y w h y i t i s i n t h i r d n o r m a l f o r m .  

S o l u t i o n :  

T h e t r a n s f o r m e d s c h e m a i s i n t h i r d n o r m a l f o r m . B y e x a m i n i n g , t h e t h r e e f u n c t i o n a l d e p e n d e n c i e s ,  

w e n d o u t t h e f o l l o w i n g :  

• T h e L . H . S . o f t h e r s t F D i s a s u p e r k e y i n t h e r e l a t i o n R 1 .  

• T h e L . H . S . o f t h e s e c o n d F D i s a s u p e r k e y i n t h e r e l a t i o n R 2 .  

• T h e L . H . S . o f t h e t h i r d F D i s a s u p e r k e y i n t h e r e l a t i o n R 3 .  

Page 10: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 10/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  9 

E x e r c i s e 6   ( 5 + 8 = 1 3 M a r k s )  

G i v e n t h e f o l l o w i n g r e l a t i o n a l s c h e m a   R(A,B,C,D,E,F ) w i t h t h e f o l l o w i n g f u n c t i o n a l d e p e n d e n c i e s :  

B , C  → D 

A  → B , F 

C  → B , D 

C , D  → E , F 

B  → F 

a ) P r o v e w h y   {A,C } i s t h e o n l y c a n d i d a t e k e y .  

S o l u t i o n :  

• C o m p u t e t h e a t t r i b u t e c l o s u r e o f   A C  : 

A C + = { A , C , B , F , D , E }  

S i n c e a l l a t t r i b u t e s i n   R  a r e i n   A C  + , w e c o n c l u d e t h a t   A C  + i s a s u p e r k e y .  

• C o m p u t e t h e a t t r i b u t e c l o s u r e o f p r o p e r s u b s e t s o f   A C  + . 

A + = { A , B , F }  

C + = { C , B , D , E , F }  

S i n c e n i e t h e r   A  + n o r  C  + c o n t a i n s a l l a t t r i b u t e s i n   R  , t h e n   A C  + i s a c a n d i d a t e k e y .  

• C o m p u t e t h e a t t r i b u t e c l o s u r e o f a l l l e f t - h a n d - s i d e s :  

B C + = { B , C , D , E , F }  

C D + = { C , D , B , E , F }  

B + = { B , F }  

S i n c e n o n e o f t h e m c o n t a i n s a l l a t t r i b u t e s o f   R  , t h e n   A C  + i s t h e o n l y c a n d i d a t e k e y .  

Page 11: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 11/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  1 0 

b ) U s i n g t h e a l g o r i t h m d e s c r i b e d i n t h e l e c t u r e s , t r a n s f o r m t h e a b o v e r e l a t i o n a l s c h e m a i n t o t h i r d  

n o r m a l f o r m . Y o u h a v e t o a p p l y a l l s t e p s o f t h e a l g o r i t h m s t a r t i n g b y c a l c u l a t i n g t h e m i n i m a l c o v e r .  

S o l u t i o n :  

• C o m p u t e M i n i m a l C o v e r :  

  B C - > D  

C o m p u t e   B C  +  = { B , C , D , E , F }  . T h e r e f o r e , t h i s F D c a n b e r e m o v e d .  

  A - > B  

C o m p u t e   A  +  = { A , F }  . T h e r e f o r e , t h i s F D c a n n o t b e r e m o v e d .  

  A - > F  

C o m p u t e   A  +  = { A , B , F }  . T h e r e f o r e , t h i s F D c a n b e r e m o v e d .  

  C - > B  

C o m p u t e   C  +  = { C , D , E , F }  . T h e r e f o r e , t h i s F D c a n n o t b e r e m o v e d .  

  C - > D  

C o m p u t e   C  +  = { C , B }  . T h e r e f o r e , t h i s F D c a n n o t b e r e m o v e d .  

  C D - > E  

C o m p u t e   C D  +  = { C , D , B , F , D }  . T h e r e f o r e , t h i s F D c a n n o t b e r e m o v e d .  

  C D - > F  

C o m p u t e   C D  +  = { C , D , B , E , F }  . T h e r e f o r e , t h i s F D c a n b e r e m o v e d .  

  B - > F  

C o m p u t e   B  +  = { B , F }  . T h e r e f o r e , t h i s F D c a n n o t b e r e m o v e d .  

T h e r e m a i n i n g s e t o f F D s i s   G = \ { A - > B , C - > B , C - > D , C D - > E , B - > F \ }  

• S i m p l i f y i n g L H S f o r t h e d e p e n d e n c y   C D - > E  . C h e c k f o r   C - > E   : 

C  + u s i n g t h e g i v e n s e t =   { C , B , D , E , F }  

C D  + u s i n g G =   { C , D , B , E , F }  

T h e n e w s e t o f F D s ,  X = { A - > B , C - > B , C - > D , C - > E , B - > F }  

• D e c o m p o s e t h e r e l a t i o n R :  

R 1 ( A , B )  

- - - 

R 1 . B r e f e r e n c e s R 3  

R 2 ( C , B , D , E )  

- - - 

R 2 . B r e f e r e n c e s R 3  

R 3 ( B , F )  

Page 12: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 12/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  1 1 

E x e r c i s e 7   ( 8 M a r k s )  

G i v e n t h e f o l l o w i n g r e l a t i o n s c h e m e a b o u t b r e a k f a s t c e r e a l s .  

c e r e a l s ( C E , S E , F A , P R , T C , F I , S U , O C , C A , F C )  

w h e r e   C E  i s t h e p r i m a r y k e y a n d t h e f u n c t i o n a l d e p e n d e n c i e s a r e :  

F A , P R , T C  → C A 

F I , S U , O C   → T C 

F A  → F C 

( A b b r e v i a t i o n s : C E = c e r e a l , S E = s e r v i n g s i z e , F A = f a t g r a m s , P R = p r o t e i n g r a m s , T C = t o t a l c a r b  

g r a m s , F I = b e r g r a m s , S U = s u g a r g r a m s , O C = o t h e r c a r b g r a m s , C A = C a l o r i e s , F C = f a t C a l o r i e s )  

D e c o m p o s e t h i s r e l a t i o n i n t o a d a t a b a s e s c h e m a i n B C N F . T r y t o p r o d u c e a s c h e m e t h a t p r e s e r v e s t h e  

F D s . B e s u r e t o i n d i c a t e c l e a r l y w h i c h t a b l e s a r e i n y o u r n a l s c h e m a a n d w h a t t h e k e y i s f o r e a c h t a b l e .  

S o l u t i o n :  

R 1 ( C E , S E , F A , P R , F I , S U , O C )  

R 2 ( F A , P R , T C , C A )  

R 3 ( F I , S U , O C , T C )  

R 4 ( F A , F C )  

Page 13: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 13/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  1 2 

E x e r c i s e 8   ( 5 M a r k s )  

S u p p o s e t h a t e a c h f u n c t i o n a l d e p e n d e n c y i n a s e t  F  o f f u n c t i o n a l d e p e n d e n c i e s o n a r e l a t i o n a l s c h e m e  R

s a t i s e s t h e c o n d i t i o n s f o r T h i r d N o r m a l F o r m ( 3 N F ) . S u p p o s e w e u s e A r m s t r o n g ' s t r a n s i t i v i t y r u l e t o  

o b t a i n   X → Z  f r o m   X → Y  a n d  Y  → Z  i n  F , w h e r e  X,Y, a n d  Z  a r e s e t s o f a t t r i b u t e s o f  R . S h o w t h a t  

X → Z  s a t i s e s t h e c o n d i t i o n s f o r 3 N F i n t h e c a s e t h a t n e i t h e r  X  n o r  Y  i s a s u p e r k e y . B e p r e c i s e .  

S o l u t i o n :  

F i r s t n o t e t h a t t h e c o n d i t i o n s o f 3 N F f o r a f u n c t i o n a l d e p e n d e n c y X - > Y :  

( 1 s t ) X i s a s u p e r k e y . ( 3 r d ) Y i s a p r i m e a t t r i b u t e  

S u p p o s e w e u s e A r m s t r o n g ' s t r a n s i t i v i t y r u l e t o o b t a i n X - > Z f r o m X - > Y a n d Y - > Z a n d n e i t h e r X  

n o r Y i s a s u p e r k e y . W e n e e d t o s h o w t h a t X - > Z s a t i s e s t h e c o n d i t i o n s f o r 3 N F . T h e 2 n d c o n d i t i o n o f  

3 N F m u s t h o l d f o r e a c h o f X - > Y a n d Y - > Z ; s i n c e t h e 1 s t c o n d i t i o n r e q u i r e s X a n d Y b e s u p e r k e y s ,  

r e s p e c t i v e l y . A p p l y i n g t h e s e c o n d c o n d i t i o n t o Y - > Z t e l l s u s t h a t e a c h a t t r i b u t e i n Z i s p r i m e . T h e r e f o r e ,  

i n t h e F D X - > Z , Z i s a p r i m e a t t r i b u t e a n d t h e F D i s i n 3 N F .  

Page 14: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 14/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  1 3 

E x t r a P a g e  

Page 15: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 15/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  1 4 

E x t r a P a g e  

Page 16: Finalexam Ws2011 2012 Databases

8/2/2019 Finalexam Ws2011 2012 Databases

http://slidepdf.com/reader/full/finalexam-ws2011-2012-databases 16/16

D a t a b a s e s I , F i n a l E x a m , J a n u a r y 1 1 , 2 0 1 2 P a g e  1 5 

E x t r a P a g e