Sie sind auf Seite 1von 14

c 

c

? ?
   ?

? The relational Model of Data is based on the concept of a c 

? The strength of the relational approach to data management comes from the formal
foundation provided by the theory of relations

? ?
   ?

? Ê Relation is a mathematical concept based on the ideas of sets

? The model was first proposed by Dr. E.F. Codd of IBM Research in 1970 in the following
paper:

? ÿÊ Relational Model for Large Shared Data Banks,ÿ Communications of the ÊCM,
June 1970

? The above paper caused a major revolution in the field of database management and earned
Dr. Codd the coveted ÊCM Turing Êward

|? ?

? Informally, a  looks like a  of values.

? Ê relation typically contains a ?? .

? The data elements in each  represent certain facts that correspond to a real-world 
or  

? In the formal model, rows are called   ?

? Each  has a column header that gives an indication of the meaning of the
data items in that column

? In the formal model, the column header is called an ? (or just
)

 
 
   !   "# $ %"&
c     c
?

?

|   

? Oey? ??e  ?

? ‘c ? ?
s??v e? ?? ?e ? ?se? ?e s ?
?  e y? ees?
? ?
?
e? e?

? — e ?
e? ?

? |?
e?S U
‘ ? e ?SS ?s?
e?ey?

? S ees? - s? ?se e ? es?e?sse ?s?eys? ? ey?


e? s?
?? e?

? — e ?  
 ? ? 
 ?

£   

? 
e? ? ??e  ?s?
e? e? ? es?
?s?e  ?sc
e?

? Ê       ?s? e e ?y??


  
????????????????? 1?? ??? ??

? 
e?à ? ?Ê
s? e e ?y?à 
??

F  ?e s??Sc


e?

? 
e?! ? ? esc ? ??e  ?

    
       % '
?
c  c

? Denoted by R(Ê1, Ê, .....Ên)

? R is the  of the relation

? The  of the relation are Ê1, Ê, ..., Ên

 ?

CSTOMER (Cust-id, Cust-name, Êddress, Phone#)

? C STOMER is the relation name

? Defined over the four attributes: Cust-id, Cust-name, Êddress, Phone#

? Each attribute has a  or a set of valid values.

? For example, the domain of Cust-id is 6 digit numbers.

£? ?? ?

? Ê   is an ordered set of values (enclosed in angled brackets ͚<  >͛)

? Ê row in the CSTOMER relation is a 4-tuple and would consist of four values, for example:

? <6395, ÿJohn Smithÿ, ÿ101 Main St. Êtlanta, GÊ 3033ÿ, ÿ(404) 94-000ÿ>

? This is called a 4-tuple as it has 4 values

? Ê tuple (row) in the C STOMER relation.

? Ê relation is a ?of such tuples (rows)

£? ???

? Ê  has a logical definition:

? Example: ͞ SÊphonenumbers͟ are the set of 10 digit phone numbers valid in the
.S.

? Ê domain also has a data-type or a format defined for it.

? The SÊphonenumbers may have a format: (ddd)ddd-dddd where each d is a


decimal digit.

? Dates have various formats such as year, month, date formatted as yyyy-mm-dd, or
as dd mm,yyyy etc.

? The attribute name designates the role played by a domain in a relation:

? °sed to interpret the meaning of the data elements corresponding to that attribute

? Example: The domain Date may be used to define two attributes named ͞Invoice-
date͟ and ͞Payment-date͟ with different meanings
 
 
   !   "# $ %"(
c  c

£? ???

? The ?  is a subset of the Cartesian product of the domains of its attributes

? each domain contains the set of all possible values the attribute can take.

? Example: attribute Cust-name is defined over the domain of character strings of maximum
length 5

? dom(Cust-name) is varchar(5)

? The role these strings play in the C°STOMER relation is that of the    !  ".

£? ??:

? Formally,

? Given R(Ê1, Ê, .........., Ên)

? r(R) * dom (Ê1) X dom (Ê) X ....X dom(Ên)

? R(Ê1, Ê, , Ên) is the  of the relation

? R is the  of the relation

? Ê1, Ê, , Ên are the  of the relation


#
? r(R): a specific  (or ÿvalueÿ or ͞population͟) of relation R  this is a Ô    Ô (rows)

£? ?? ?

? Let R(Ê1, Ê) be a relation schema:

? Let dom(Ê1) = {0,1}

? Let dom(Ê) = {a,b,c}

? Then: dom(Ê1) X dom(Ê) is all possible combinations:

{<0,a> , <0,b> , <0,c>, <1,a>, <1,b>, <1,c> }

? The relation state r(R) * dom(Ê1) X dom(Ê)

? For example: r(R) could be {<0,a> , <0,b> , <1,c> }

? this is one possible state (or ͞population͟ or ͞extension͟) r of the relation R, defined
over Ê1 and Ê.

? It has three -tuples: <0,a> , <0,b> , <1,c>

 
 
   !   "# $ %")
c     c
?
G !

|  ?es?? ? F  ?es??

 e? ? e  ??

$
— ?e e? ?  e?

$
? ss e?— ? es? ?  ?

 ? ?   e?

? ? ?

 e?e ? ? Sc
e? ??e  ?

 e ? e? ? Se? ?


e?e  ?

    
       % *
?
c     c
?

     

? Y e? ?  es???e  ??

? 
e?  es?e? %
   
%

  ?eve?

?
ey?e? ?e??
e?
 ? ?

? Y e? ? es???e  ?sc


e?? ? ?v es? 
?ec
?  e?
& & &
?  e?  ?c s e?
e? es?? 1? ?? ? ?
e?v es??=<v1?v??
v>? ?e?  ee ??

?  eve?? e?ee ? eve? e ?? ?e  ? es? ?e e?

s?  e?

!    £ 


       

     

?  es???  e?

? Ê ?v es?e?c s ee ? c? vs e?

? ‘c
?v e???  e? s?e? ?
e? ? ?
e? e? ?
?c ?

? |?  e??=?<v1?v??v>?s??  e? ??


e?e  ?se?? ?Ê1?Ê?
?Ê?

? 
e?ec
?u ? s?e??v e? ?'Ê
?

? Ê?sec ??v e?s? se ? ?eese?v es?


?e?  ? ? c e? ?
ce?  es??

    
       % +
?
c  c

   ??  ?

? potation:

?  e refer to  ?  of a tuple t by:

? t[Êi] or t.Êi

? This is the value vi of attribute Êi for tuple t

? Similarly, t[Êu, Êv, ..., Êw] refers to the subtuple of t containing the values of
attributes Êu, Êv, ..., Êw, respectively in t

?|( ?
  ?

? Constraints are   that must hold on  valid relation states.

? There are three   Ô of constraints in the relational model:

? O constraints

?  )  constraints

? ?*  constraints

? Ênother implicit constraint is the  constraint


+
? Every value in a tuple must be from the    Ô ,   (or it could be , if
allowed for that attribute)

O?
  :

?  ! of R:

? Is a set of attributes SK of R with the following condition:

? po two tuples in any valid relation state r(R) will have the same value for SK

? That is, for any distinct tuples t1 and t in r(R), t1[SK] o t[SK]

? This condition must hold in  u Ô r(R)

? O of R:

? Ê ÿminimalÿ superkey

? That is, a key is a superkey K such that removal of any attribute from K results in a
set of attributes that is not a superkey (does not possess the superkey uniqueness
property)

?
 
 
   !   "# $ %",
c     c
?
‘ 

? ‘ yee e?Ê ess?SS ?‘ yee| ?


e‘?

? <SS ? e?Ê ess>?

? <SS ? e>?

? <SS >?

? Ê ?
e? ve?e?s e?ey?

| 

? Êy? ?s??  
 ? ?vce?ves?
-
? Êy?se? ? es?
?   

 ?s??  
?
.
? Ê?ë  ë ?s eey?s? s ??ey?

? |??e  ?
s?seve ?     ? e?s?c
se? y? ?e?
e?  ??

? 
e?y?ey? es?e?  e e ?

? ‘ e?— s e?


e?—Ê?e  ?sc
e?

? —ÊSe?e#?Se ?!e?! e ?"e?

?  e?c
se?Se ?s?
e?y?ey?

? 
e?y?ey?v e?s? se ? ?  
  / ?ec
?  e???e  ?

?  v es?
e?  e? ey?

? Ê s ? se ? ?    ?
e?  e? ? 
e?  e??

? Vee ? e?—
se?s?y?ey?
e?s es? ?
e?c  e?eys??es? ?
s#e?

? ? ys? c e??c


ce?s?s ees?s jecve?

Ê 
 
              

    
       % -
?
c     c
?
?

 G  ! 

?  G  ! ?

? Ê?se?S? ?e  ?sc


es?
?e ? ?
e?se? se?

? S?s?
e?e? ?
e?
e?   ?

? S?=?{1???}?

? 1????e?
e?es? ?
e? v  ?  ? 
?
e? se?S?

? F ?s  e?s
s??—Y! Ê "? se?sc
e? 
?6?e  ?sc
es?

Ê  G  ! 

    
       % .
?
c  c

?|0 ?

? ?|1 

? The       Ô PK of each relation schema R in S cannot have null values
in any tuple of r(R).
2
? This is because primary key values are used to    the individual tuples.

? t[PK] o null for any tuple t in r(R)

? If PK has several attributes, null is not allowed in any of these attributes

? pote: Other attributes of R may be constrained to disallow null values, even though
they are not members of the primary key.

?|3 ?

? Ê constraint involving  relations

? The previous constraints involve a single relation.

? °sed to specify a   among tuples in two relations:

? The  4 ??and the   ?.

?|4 ?

? Tuples in the  5 ? R1 have attributes FK (called 5 ?! attributes) that
reference the primary key attributes PK of the   ? R.

? Ê tuple t1 in R1 is said to   a tuple t in R if t1[FK] = t[PK].

? Ê referential integrity constraint can be displayed in a relational database schema as a


directed arc from R1.FK to R.

Referential Integrity (or foreign key) Constraint:

? Statement of the constraint

? The value in the foreign key column (or columns) FK of the the  6 ?
R1 can be :

? (1) a value of an existing primary key value of a corresponding primary key


PK in the   ? R, or

? () a .

? In case (), the FK in R1 should  be a part of its own primary key.

Displaying a relational database schema and its constraints:

 
 
   !   "# $ %"&/
c     c
?
? ‘c
?e  ?sc
e?c?e? s ye ?s?? ? ? e?es?

? 
e?e? ?
e?e  ?s? e? ve?
e? e?es?

? 
e?y?ey? e? ? es?  ?e?  e e ?

? Ê? e?ey?eee ?ey?c ss?s? s ye ?s?? ece ?c? ? ?
e?
 e?ey? es? ?
e?eeece ? e?

? —? s ? ?
e?
e?y?ey? ?
e?eeece ?e  ? ?c y?

? e?s  e?s
s?
e?—Y! Ê "?  ?

 |
  
Ê    

    

? ‘c
?  7 ?  ?
ve?y?  es??s?c e?e  ?se?

? 
e?  8 
 8 
 ?s??  ? ? ?
e? v  ?e  ?ses?

?  
eeve?
e? se?s?c
e ??e ?se?ses?

? Bsc? e s? ?c


?
e? se?

    
       %
?
c     c
?
? | S‘??e ?  e???e  ?

? ‘‘‘??es?  e? ??e  ?

? !Y|F"?? e? ??es?  e??

? e?s  e?s
s??e e?se? ?
e?—Y! Ê "? se?

     


Ê 

      

? | S‘??  e?

? ‘‘‘??  e?

? !Y|F"??  e?

    
       % '
?
c  c

? Integrity constraints should not be violated by the update operations.

? Several update operations may have to be grouped together.

? °pdates may  9  to cause other updates automatically. This may be necessary to
maintain integrity constraints.

In case of integrity violation, several actions can be taken:

? Cancel the operation that causes the violation (RESTRICT or REJECT option)

? Perform the operation but inform the user of the violation

? Trigger additional updates so the violation is corrected (CÊSCÊDE option, SET p°LL
option)

? Execute a user-specified error-correction routine

ï ?  ?? ? ?

? IpSERT may violate any of the constraints:

? Domain constraint:

? if one of the attribute values provided for the new tuple is not of the
specified attribute domain

? Key constraint:

? if the value of a key attribute in the new tuple already exists in another tuple
in the relation

? Referential integrity:

? if a foreign key value in the new tuple references a primary key value that
does not exist in the referenced relation

? Entity integrity:

? if the primary key value is null in the new tuple

ï ?  ?? ? :

? DELETE may violate only referential integrity:

? If the primary key value of the tuple being deleted is referenced from other tuples in
the database

? Can be remedied by several actions: RESTRICT, CÊSCÊDE, SET p°LL

? RESTRICT option: reject the deletion

 
 
   !   "# $ %"&(
c  c

? CÊSCÊDE option: propagate the new primary key value into the
foreign keys of the referencing tuples

? SET p°LL option: set the foreign keys of the referencing tuples to
p°LL

? One of the above options must be specified during database design for each foreign
key constraint

? °PDÊTE may violate domain constraint and pOT p°LL constraint on an attribute being
modified

? Êny of the other constraints may also be violated, depending on the attribute being
updated:

? °pdating a foreign key (FK):

? May violate referential integrity

? °pdating an ordinary attribute (neither PK nor FK):

? Can only violate domain constraints

|"
 ?  ?

Consider the following relations for a database that keeps track of student enrollment in courses
and the books adopted for each course:

ST°DEpT(SSp, pame, Major, Bdate)

CO°RSE(Course#, Cname, Dept)

EpROLL(SSp, Course#, Quarter, Grade)

BOOKÊDOPTIOp(Course#, Quarter, BookISBp)

TEXT(BookISBp, BookTitle, Publisher, Êuthor)


:
G    Ô    Ô        Ô  Ô Ô 

 
 
   !   "# $ %"&)