2 Entity-Relationship Model - Ser_2

download 2 Entity-Relationship Model - Ser_2

of 7

Transcript of 2 Entity-Relationship Model - Ser_2

  • 7/30/2019 2 Entity-Relationship Model - Ser_2

    1/7

    2 . T H E E N T I T Y - R E L A T I O N S H I P M O D E L

    ( E - R M o d e l )

    T h e E - R m o d e l w a s d e v e l o p e d b y P e t e r C h e n i n t h e m i d - 7 0 ' s , a n d e x t e n d e d b y h i m a n d o t h e r s

    i n 8 0 ' s . T h e E - R m o d e l i s s t i l l b r o a d l y u s e d i n l o g i c a l ( c o n c e p t u a l ) d a t a b a s e d e s i g n .

    T h e \ w o r l d " i s d e s c r i b e d i n t e r m s o f

    { e n t i t i e s

    { r e l a t i o n s h i p s

    { a t t r i b u t e s

    A s c h e m a i n E - R m o d e l c a n b e v i s u a l i z e d b y c r e a t i n g a n E - R d i a g r a m .

    E n t i t y - R e l a t i o n s h i p m o d e l c a n b e u s e d a s

    { a t o o l f o r d a t a m o d e l i n g a n d l o g i c a l d a t a b a s e d e s i g n ( s p e c i c a t i o n o f a n e n t e r p r i s e

    s c h e m a ) ,

    { a f o r m a l s p e c i c a t i o n o f o v e r a l l s y s t e m d a t a s t r u c t u r e ,

    { a t o o l f o r n e w c o m e r s t o l e a r n d a t a b a s e c o n c e p t s a n d s t r u c t u r e ,

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

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

    2 . 1 B a s i c C o n c e p t s

    E n t i t y i n s t a n c e ( e ) : a d i s t i n g u i s h a b l e t h i n g , p e r s o n , o r e v e n t . . .

    E n t i t y s e t ( E ) : a s e t o f e n t i t y i n s t a n c e s o f t h e s a m e t y p e .

    E x a m p l e s :

    { s t u d e n t s c u r r e n t l y r e g i s t e r e d a t U O G

    { i g h t s o e r e d b y A i r C a n a d a

    { S e a r s c r e d i t c a r d h o l d e r s

    1

  • 7/30/2019 2 Entity-Relationship Model - Ser_2

    2/7

    R e l a t i o n s h i p ( r ) : r e p r e s e n t s t h e f a c t t h a t c e r t a i n e n t i t i e s a r e r e l a t e d t o e a c h o t h e r i n a

    s p e c i e d w a y .

    R e l a t i o n s h i p s e t ( R ) : a s e t o f r e l a t i o n s h i p s o f t h e s a m e t y p e .

    E x a m p l e s :

    { s t u d e n t s r e g i s t e r e d i n a c o u r s e

    { p a s s e n g e r s b o o k e d o n a i g h t

    { b o o k s o n l o a n t o l i b r a r y p a t r o n s

    { p a r e n t - c h i l d r e l a t i o n s h i p

    M a t h e m a t i c a l r e p r e s e n t a t i o n o f r e l a t i o n s h i p s e t :

    R = f ( e

    1

    e

    2

    : : : e

    n

    ) k e

    1

    2 E

    1

    e

    2

    2 E

    2

    : : : e

    n

    2 E

    n

    g

    T e a c h i n g = f ( p s ) k p 2 P r o f e s s o r s 2 S e c t i o n g

    N o t e t h a t a r e l a t i o n s h i p s e t c a n n o t e x i s t u n l e s s a l l e n t i t y i n s t a n c e s i n v o l v e d i n t h e r e l a t i o n s h i p

    e x i s t .

    A t t r i b u t e : d e s c r i b e s a p r o p e r t y o f a n e n t i t y o r a r e l a t i o n s h i p

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

    E x a m p l e s :

    { S t u d e n t : I D , n a m e , d e p a r t m e n t , . . .

    { B o o k o n l o a n : l o a n d a t e , d u e d a t e , . . .

    A n a t t r i b u t e v a l u e i s d r a w n f r o m a c e r t a i n d o m a i n o r v a l u e s e t .

    E - R d i a g r a m :

    { A n E - R d i a g r a m i s a g r a p h i c a l r e p r e s e n t a t i o n o f a s c h e m a i n E - R m o d e l .

    { A n E - R d i a g r a m u t i l i z e s t h e f o l l o w i n g n o t a t i o n s :

    2

  • 7/30/2019 2 Entity-Relationship Model - Ser_2

    3/7

    R e c t a n g l e s r e p r e s e n t e n t i t y s e t s

    E l l i p s e s r e p r e s e n t a t t r i b u t e s

    D i a m o n d s r e p r e s e n t r e l a t i o n s h i p s e t s

    L i n e s l i n k a t t r i b u t e s t o e n t i t y s e t s a n d e n t i t y s e t s t o r e l a t i o n s h i p s e t s .

    { N o s t a n d a r d n o t a t i o n s h a v e b e e n d e n e d .

    2 . 2 R e l a t i o n s h i p D e g r e e a n d C a r d i n a l i t y

    R e l a t i o n s h i p d e g r e e :

    { U n a r y r e l a t i o n s h i p : r e l a t i o n s h i p b e t w e e n a n e n t i t y s e t a n d i t s e l f

    { B i n a r y r e l a t i o n s h i p : r e l a t i o n s h i p b e t w e e n t w o e n t i t y s e t s .

    { N - a r y r e l a t i o n s h i p s : r e l a t i o n s h i p b e t w e e n n e n t i t y s e t s .

    { N o t e t h a t

    B o t h e n t i t y s e t s a n d r e l a t i o n s h i p s e t s m a y h a v e a t t r i b u t e s

    E n t i t i e s m u s t h a v e k e y s a n d

    R e l a t i o n s h i p s c a n b e i d e n t i e d b y t h e ( c o m b i n e d ) k e y s o f t h e p a r t i c i p a t i n g e n t i t i e s .

    C a r d i n a l i t y :

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

    a s s o c i a t e d v i a a r e l a t i o n s h i p s e t .

    { O n e t o o n e ( 1 : 1 )

    E a c h e n t i t y i n s t a n c e i n A i s r e l a t e d t o a t m o s t o n e e n t i t y i n s t a n c e i n B a n d s i m i l a r l y f o r

    e a c h e n t i t y i n s t a n c e i n B .

    { O n e - t o - m a n y ( 1 : M )

    A n e n t i t y i n s t a n c e i n B i s r e l a t e d t o a t m o s t o n e e n t i t y i n s t a n c e i n A , b u t a n e n t i t y

    i n s t a n c e i n A c a n b e r e l a t e d t o m a n y e n t i t y i n s t a n c e s i n B .

    3

  • 7/30/2019 2 Entity-Relationship Model - Ser_2

    4/7

    { M a n y - t o - m a n y ( M : M )

    A n e n t i t y i n s t a n c e i n A c a n b e r e l a t e d t o m a n y e n t i t y i n s t a n c e s i n e n t i t y s e t B , a n d v i c e

    v e r s a .

    { I n a n E - R d i a g r a m , w e c a n u s e d i r e c t e d l i n e s ( a r r o w s ) t o s p e c i f y c a r d i n a l i t y . A n e n t i t y

    s e t p o i n t e d b y a n a r r o w i s a \ o n e " e n t i t y s e t i n a r e l a t i o n s h i p s e t .

    W e a k e n t i t y s e t a n d e x i s t e n c e d e p e n d e n c y :

    { T h e e x i s t e n c e o f e n t i t y s e t A d e p e n d s o n t h e e x i s t e n c e o f e n t i t y s e t B . A i s s a i d t o b e

    d e p e n d e n t o n B . B i s s a i d t o b e a s t r o n g e n t i t y s e t ( p a r e n t e n t i t y ) a n d A i s a w e a k

    e n t i t y s e t ( c h i l d e n t i t y ) i n t h e r e l a t i o n s h i p .

    { A n e n t i t y i n a w e a k e n t i t y s e t c a n n o t e x i s t u n l e s s s o m e o t h e r e n t i t y e x i s t s ( i n t h e s t r o n g

    e n t i t y s e t )

    M o r e t h a n o n e r e l a t i o n s h i p s e t m a y e x i s t b e t w e e n t w o e n t i t y s e t s

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

    2 . 3 K e y s

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

    a n e n t i t y i n s t a n c e i n a n e n t i t y s e t u n i q u e l y .

    E x a m p l e :

    { f s t u d e n t I D , n a m e g

    { f s o c i a l i n s u r a n c e n u m b e r , a d d r e s s g

    { f r o w n u m b e r , c o l u m n n u m b e r g

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

    a s u p e r k e y .

    E x a m p l e :

    4

  • 7/30/2019 2 Entity-Relationship Model - Ser_2

    5/7

    { f s t u d e n t I D g

    { f s o c i a l i n s u r a n c e n u m b e r g

    { f r o w n u m b e r , c o l u m n n u m b e r g

    P r i m a r y k e y : a c a n d i c a t e k e y c h o s e n b y d a t a b a s e d e s i g n e r a s t h e p r i n c i p a l m e a n s o f i d e n -

    t i f y i n g e n t i t i e s w i t h i n a n e n t i t y s e t .

    E x a m p l e :

    { f s t u d e n t I D g

    P r i m a r y k e y s e l e c t i o n c r i t e r i a :

    { n o t c h a n g e o v e r t i m e

    { n o n u l l v a l u e

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

    u n i q u e ) , a d i s c r i m i n a t o r i s s e l e c t e d f o r t h e w e a k e n t i t y s e t .

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

    e n t i t i e s t h a t a r e a l l d e p e n d e n t o n o n e p a r t i c u l a r s t r o n g e n t i t y s e t .

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

    f S e c t i o n n u m b e r g

    { T h e p r i m a r y k e y o f a w e a k e n t i t y s e t c a n b e f o r m e d b y t h e p r i m a r y k e y o f t h e s t r o n g

    e n t i t y s e t o n w h i c h i t i s e x i s t e n c e d e p e n d e n t , p l u s i t s d i s c r i m i n a t o r .

    E x a m p l e :

    f C o u r s e n a m e , s e c t i o n n u m b e r g

    o r , f C o u r s e n u m b e r , s e c t i o n n u m b e r g

    2 . 4 E x t e n s i o n s o f t h e E - R m o d e l

    ( S p e c i a l R e l a t i o n s h i p s )

    G e n e r a l i z a t i o n :

    5

  • 7/30/2019 2 Entity-Relationship Model - Ser_2

    6/7

    { G e n e r a l i z a t i o n f o r m s a n e w ( h i g h e r - l e v e l ) e n t i t y s e t ( s u p e r s e t ) a s t h e u n i o n o f t w o o r

    m o r e ( l o w e r - l e v e l ) e n t i t y s e t s ( s u b s e t s ) .

    { A t t r i b u t e s t h a t a r e c o m m o n t o a l l s u b s e t s e n t i t i e s a r e p l a c e d i n t h e s u p e r s e t e n t i t i e s .

    { A s u p e r s e t i s a g e n e r i c e n t i t y s e t t h a t i s s u b d i v i d e d i n t o s u b s e t s . A s u b s e t i s a s u b s e t

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

    { I S A r e l a t i o n s h i p i s t h e r e l a t i o n s h i p b e t w e e n e a c h s u b s e t a n d i t s s u p e r s e t .

    S p e c i a l i z a t i o n ( C a t e g o r i z a t i o n ) :

    { S p e c i a l i z a t i o n f o r m s a n e w e n t i t y s u b s e t b y t a k i n g a s u b s e t o f a n e n t i t y s u p e r s e t .

    { S p e c i a l i z a t i o n a n d g e n e r a l i z a t i o n a r e g e n e r a t e d i n t h e o p p o s i t e d i r e c t i o n s .

    { E x h a u s t i v e s u b s e t s : A l l s u b s e t s a r e d e n e d f o r a s u p e r s e t .

    { E x c l u s i v e s u b s e t s : S u b s e t s h a v e n o o v e r l a p s . E a c h i n s t a n c e o f t h e s u p e r s e t i s r e q u i r e d

    t o b e a m e m b e r o f e x a c t l y o n e s u b s e t .

    { N o n e x h a u s t i v e s u b s e t : S o m e ( n o t a l l ) o f t h e s u b s e t s h a v e b e e n d e n e d f o r a s u p e r s e t .

    { N o n e x c l u s i v e s u b s e t : S u b s e t s m a y o v e r l a p . A n i n s t a n c e o f t h e s u p e r s e t m a y s i m u l t a -

    n e o u s l y b e l o n g t o m o r e t h a n o n e s u b s e t .

    A g g r e g a t i o n :

    { A g g r e g a t i o n m o d e l s t h e r e l a t i o n s h i p o f \ i s a p a r t o f " .

    { I t a l l o w s m o d e l l i n g o f r e l a t i o n s h i p s b e t w e e n a g g r e g a t e d p a r t s o f a s c h e m a .

    2 . 5 L o g i c a l d a t a m o d e l i n g i n t h e E - R m o d e l

    T h e g e n e r a l a p p r o a c h f o r l o g i c a l m o d e l i n g i n t h e E - R m o d e l :

    I n f o r m a t i o n f o r l o g i c a l m o d e l i n g c o m e s f r o m t h e p r o b l e m s t a t e m e n t , e x p e r t k n o w l e d g e o f t h e

    a p p l i c a t i o n d o m a i n , a n d g e n e r a l k n o w l e d g e o f t h e r e a l w o r l d .

    I d e n t i f y e n t i t y a n d r e l a t i o n s h i p s e t s r s t .

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

    6

  • 7/30/2019 2 Entity-Relationship Model - Ser_2

    7/7

    T h e n c o m b i n e a n d o r g a n i z e e n t i t y s e t s u s i n g g e n e r a l i z a t i o n ( s p e c i a l i z a t i o n ) a n d a g g r e g a t i o n .

    I n - C l a s s E x e r c i s e 1

    A u n i v e r s i t y i s d e s i g n i n g a s y s t e m t o s t o r e i n f o r m a t i o n a b o u t c o u r s e s , c o u r s e o e r i n g , i n s t r u c t o r s

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

    A c o u r s e m a y h a v e p r e r e q u i s i t e s . A c o u r s e m a y b e o e r e d o n c e t o t h r e e t i m e s , o r n o t b e o e r e d .

    A c o u r s e o e r i n g m a y b e t a u g h t b y o n e o r m o r e p r o f e s s o r s . A p r o f e s s o r m a y t e a c h z e r o , o n e o r

    m o r e c o u r s e o e r i n g s . A c o u r s e ( o e r i n g ) m a y b e t a u g h t i n o n e o r m o r e c l a s s r o o m s . A c l a s s r o o m

    m a y b e u s e d f o r z e r o , o n e o r m o r e c o u r s e o e r i n g s .

    I n - C l a s s E x e r c i s e 2

    A u n i v e r s i t y i s d e s i g n i n g a s y s t e m t o s t o r e i n f o r m a t i o n a b o u t c o u r s e s , c o u r s e o e r i n g , i n s t r u c t o r s

    a n d c l a s s r o o m s .

    A c o u r s e m a y h a v e p r e r e q u i s i t e s . A c o u r s e m a y b e o e r e d o n c e t o t h r e e t i m e s , o r n o t b e o e r e d .

    A c o u r s e ( o e r i n g ) m a y h a v e a n u m b e r o f l e c t u r e s e c t i o n s . A l e c t u r e s e c t i o n m a y b e t a u g h t b y o n e

    o r m o r e p r o f e s s o r s . A p r o f e s s o r m a y t e a c h z e r o , o n e o r m o r e c o u r s e s . A c o u r s e m a y b e t a u g h t i n

    o n e o r m o r e c l a s s r o o m s . A c l a s s r o o m m a y b e u s e d f o r z e r o , o n e o r m o r e c o u r s e s .

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

    c o u r s e s , i n c l u d i n g c o u r s e n u m b e r a n d c o u r s e t i t l e ,

    o e r i n g , i n c l u d i n g s e m e s t e r , y e a r , a n d e n r o l m e n t l i m i t ,

    s e c t i o n s , i n c l u d i n g s e c t i o n n u m b e r a n d e n r o l m e n t ,

    p r o f e s s o r s , i n c l u d i n g , I D , n a m e , p h o n e n u m b e r , o c e ,

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

    R e a d i n g : C h a p t e r 2 .

    7