• Nem Talált Eredményt

operators or inferencing rules which may be applied to the objects

1 1 3

general in tegrity ru les w h ich con strain the va lid d atab ase states or ch a n g es o f state. T h e s e are d is tin c t fro m an y a p p lic a tio n d e p e n d e n t in te g r ity ru les (su c h as sa la ry c a n n o t decrease, or n o -o n e earns m ore than their m anager).

W e sh a ll illu strate th e se c o m p o n e n ts o f th e relation al m o d e l b y c o n s id e r in g a sm a ll e x a m p le , c o n c e r n in g the parts o f a d o o r (F ig u re 1). W e can start to m o d e l th is w o r ld o f d o o r s b y the fo llo w in g relations:

Parts

partid partN am e

p 3 7 d o o r w a y

p 4 fram e

P i d o o r

p 3 h in g e

p2 m ou n tin g

p l 0 7 p iv o t

p 9 hand le

p l 2 3 s c r e w

A ssem b ly

majorPart minorPart quantity

p 3 7 p4 1

p 3 7 P i 1

P i p3 2

P i p9 1

p3 p2 2

p3 p l 0 7 1

p3 p l 2 3 8

1 1 4

T h e m o r e general w o r ld o f w h ich the d o o r is an e x a m p le ca n b e d e s c r ib e d b y the f o llo w in g relation al schema:

S C H E M A C o m p o n en ts

D O M A IN P a r tid S T R I N G D O M A IN P artN am e S T R I N G

D O M A IN C o u n t IN T E G E R

R E L A T IO N P arts

A T T R IB U T E partid D O M A IN Partid

A T T R IB U T E partN am e D O M A IN PartN am e

R E L A T IO N A s s e m b ly

A T T R IB U T E majorPart D O M A IN Partid

A T T R IB U T E m inorPart D O M A IN Partid

A T T R IB U T E quantity D O M A IN C ou n t

E N D S C H E M A C o m p o n e n ts.

T h ere is a num ber o f q u e s tio n s c o n c e rn in g su c h sch em as that w e w ish to a n s w e r from a so ftw a re te c h n o lo g ist's point o f v ie w :

what d o es it m e a n w h en w e u s e w o r d s such as IN T E G E R and S T R IN G ? what d oes it m ea n w hen w e d ecla re a D O M A IN ?

what d oes th e identifier Partid id e n tify ?

what d oes it m e a n w hen w e d e fin e a R E L A T IO N ?

IN T E G E R , ST R IN G a n d s o on are the th e p r e -d efin e d typ es o f the la n g u a g e . T h e se are ty p ica l o f typ es in current d atab ase lan gu ages.

T o a n s w e r the q u e stio n o f w h at it m ean s to d ec la r e a D O M A I N w e sh all lo o k b riefly at another e x a m p le w h ich m akes th e p oin t m ore c lea rly .

1 1 5

C om pare the data m od el declaration

D O M A IN D O M A IN

S h o e S iz e IN T E G E R C h ild sA g e IN T E G E R

w ith the program m ing lan gu age declaration

T Y P E

S h o e S iz e C h ild sA g e

1 . . 13 1 . . 13

In th e p rogram m in g la n g u a g e d eclaration both ShoeSize and ChildsAge renam e the ty p e 1 ..1 3 . In p rogram m in g term s then, d ecla rin g a d om ain ren am es a p r e -d efin e d ty p e. O n e q u estio n th is raises is w h eth er or n o t ShoeSize and ChildsAge are the sa m e ty p e . In th e data m o d el w h ic h w e are c o n sid e r in g , th ey are not; ty p in g is by n am e rather than by structure. I f in reality it m a k e s little s e n s e to co m p a re a c h ild s a g e w ith a sh o e s iz e , th is can b e r e fle c te d in the m o d el b y m a k in g it ille g a l to com p are a valu e o f ty p e ChildsAge w ith a v a lu e o f ty p e ShoeSize.

T h ere is a sm all d ifferen ce b e tw e e n type renam ing in a gen eral purpose program m ing la n g u a g e and type renam ing in the relational m od el; in the relational m o d el this renam ing m ust be d o n e .

W e n o w turn our attention to th e declaration o f relation s. C om p are the declaration o f th e relation c a lle d Parts w ith that o f the fo llo w in g array o f records :

R E L A T IO N Parts

A T T R IB U T E partid D O M A IN P artid A T T R IB U T E partN am e D O M A IN PartN am e

T Y P E

Part = R E C O R D partid partN am e

Partid;

PartN am e E N D

Parts = A R R A Y [ 1 . . n ] O F Part

1 1 6

R E C O R D is n ot its e lf

a

t y p e , u nlike, sa y , IN T E G E R , but it a llo w s ty p e s to b e con stru cted . In this e x a m p le

a

ty p e c a lle d P a r t is co n stru cted . S o , R E C O R D is a ty p e co n stru cto r. T h e op eration s a s s o c ia te d w ith any ty p e c o n stru cted u s in g th e R E C O R D ty p e co n str u c to r are fie ld referen cin g o p e r a tio n s. S im ilarly A R R A Y is a ty p e co n str u c to r , c o n str u c tin g , in th is e x a m p le , a ty p e c a lle d Parts.

Just as R E C O R D and A R R A Y are type con stru ctors in p rogram m in g la n g u a g e s, s o R E L A T IO N is a ty p e co n stru cto r in th e d a ta m od el la n g u a g e , con stru ctin g, in th is e x a m p le , a ty p e c a lle d Parts.

T h e w o rd A T T R IB U T E is sim p ly part o f th e syn tax o f a relation declaration .

T h ere is , in fact, m o re t o a relation d e c la r a tio n than w e h a v e u n c o v e r e d s o far. C o n sid e r the fo llo w in g program d eclaration s:

V A R

w : P arts

x : P arts

y : P a rtid

z : In teger

I f w e l o o k fo r s o m e t h in g e q u iv a le n t in th e data m o d e l, w e s e e n o th in g w h ic h o b v io u s ly c o r re sp o n d s, b ecau se v a r ia b le s are n ot e x p lic it ly d eclared in the r e la tio n a l m o d e l. T h ere are tw o reason fo r this. First, th ere are n o variab les w h ic h are n ot rela tio n s, s o there is n o an alogu e of:

y : P a rtid

z : In teger

S e c o n d ly , there is no c o n c e p t o f tw o v a ria b les o f the sam e typ e and s o n o a n a lo g u e of:

w : Parts

x : Parts

In the relation al m od el th ere is exactly o n e v ariab le o f each typ e. T h us d ecla rin g a relation d eclares both a ty p e and a variab le o f that type, w ith o n e nam e for both:

relation declaration = typ e declaration + variable declaration.

117

T h e o p era tio n s a sso cia ted w ith rela tio n s con stru cted u sin g th e R E L A T IO N type c o n str u c to r are largely based on the relational ca lcu lu s or relational algebra, and vary from o n e data m o d el lan gu age to another. T h ey m ay in c lu d e o p era tio n s o n relation s o f d iffe r e n t ty p e s, su ch as the u n io n o f tw o r ela tio n s. O p eration s a s so c ia te d w ith the b ase ty p es, su c h as IN T E G E R , fro m w h ich a re la tio n is con stru cted , and typ e transfer op eration s that m ap b etw een v a lu e s o f a relation type and v a lu e s o f a n o n -r e la tio n ty p e are ex tern a l to the r ela tio n a l c a lc u lu s o r algeb ra. S o a ls o are o p e r a tio n s that a c k n o w le g e that relations are variab les. C on sid er the fo llo w in g relation al algebra exp ression :

JO IN Parts W IT H

A ssem b ly O V E R

Parts .partid, A ssem b ly .m a jo rP a rt

T h is is an ex p r e ssio n , and th e r ela tio n s Parts and Assembly in it m ay b e th ou gh t o f as v a lu e s , ju st as a and b m ay be thought o f as valu es in the fo llo w in g p rogram fragm ent:

P R O C E D U R E su m ( a, b : IN T E G E R ) : IN T E G E R ; B E G IN

R E T U R N a+b E N D s u m ;

T o understand su ch a su b -se t o f a p rogram m ing lan gu age w e d o n o t n eed to k n o w that a and b are the n a m es o f variab les, ju s t that th ey d en o te valu es o f ty p e IN T E G E R . S im ilarly, in ord er to d efin e q u eries or v ie w s in a data m o d e l la n g u a g e , w e d o n ot n e e d to k n o w that id en tifiers su c h as Parts and A ssem bly are n a m es o f v a r ia b le s. H o w e v e r , w e a ls o n e e d the a b ility to upd ate a w o r k in g d atab ase, that is, to be a b le to sto re, m o d ify , or d e lete in fo r m a tio n . In th is c o n te x t w e are clea rly d ea lin g w ith variables. A statem en t such as

A P P E N D T O Parts ( partid = p l 1,

partN am e = w i n d o w )

in a data m od el language has properties in com m on w ith an a ssig n m en t statem ent in a program m ing

1 18

la n g u a g e such as:

average := s u m ( a, b ) / 2 ;

T h e relation al m o d e l p r o v id e s integrity rules (D a te 1986) that con strain the v a lu e s o f such variables in th e p resen ce o f u p d ates. A s ap p lied to the Components ex a m p le, th ese ru les are:

R u le 1: E n tity in teg rity : T h e attributes p a rtid , majorPart and m inorPart m ay n ot take n u ll v a lu e s.

R u le 2: R e fe re n tia l integrity: every v a lu e w h ic h occurs fo r the attribute minorPart and every v a lu e w h ic h o c c u r s fo r the attrib u te m ajorPart m u st a lso o c c u r as a v a lu e o f the attribute partid. T hat is, an a sse m b ly m ust c o n sist o f k n o w n parts and m ust constitute a k n o w n part, w h ere by k n o w n w e m ean k n ow n to the m o d el. W e s e e that in the c a se o f referen tial integrity, the v a lu e s o f the variables are con strain ed w ith resp ect to each other.

In o th e r w ords, th e r e la tio n ty p e s o f a sc h e m a are n o t in d ep en d en t; w e c a n c o n s id e r the w h o le sc h e m a Components as a sin g le typ e (con stru cted u sin g the p re-d efin ed ty p e con stru ctor S C H E M A and c o n s is tin g o f th e t w o rela tio n ty p es P a rts and Assembly). R e fe r e n tia l in te g r ity can then be c o n sid e r e d as an in varian t on this typ e, in the s a m e w a y as a typ e stack m a y c o n s is t o f an array type and an integer cu rsor w ith an invariant con strain in g the p o sitio n o f the cursor.

T o su m m arise, the relation al m od el g iv e s :

base ty p e renam ing

p re-d efin ed typ e constructors, R E L A T IO N and S C H E M A p re-d efin ed operations on con stru cted types

im p licit d eclaration s o f variables (o n e variable for each relation) an e x p r e ssio n su b -lan gu age b ased o n relational ca lcu lu s or algeb ra a m ean s to a ssig n v a lu es o f e x p r e ss io n s to relation variab les.