The answer yes for key and foreign key constraints
Answers to Exercises / Appendix F381
Now we could define some foreign keys:
CREATE DOMAIN CITY AS VARCHAR(20)
CONSTRAINT ... CHECK ( VALUE IN ( ‘London’ , ‘Paris’ , ‘Rome’ , ‘Athens’ , ‘Oslo’ , ‘Stockholm’ , ‘Madrid’ , ‘Amsterdam’ ) ) ;
Now we can define the CITY columns in tables S and P to be of “domain CITY” instead of type VARCHAR(20), and they’ll then “automatically” be subject to the required constraint.
8.9 |
|
---|
I’m assuming that operators CHAR_LENGTH, SUBSTR, and CAST_AS_INTEGER are available and have the obvious semantics.
TYPE POINT
POSSREP CARTESIAN { X RATIONAL , Y RATIONAL
CONSTRAINT SQRT ( X ** 2 + Y ** 2 ) ≤ 100.0 } POSSREP POLAR { R RATIONAL , THETA RATIONAL
CONSTRAINT R ≤ 100.0 } ;
Whether some shorthand could be provided that would effectively allow us to specify the constraint just once instead of once per possrep is a separate issue, beyond the scope of this book.
CX3: INSERT into S, UPDATE of SNO in S
CX4: INSERT into S, UPDATE of SNO or CITY in S
CX9: UPDATE of SNO or STATUS in S
8.14 This exercise is a little unfair, since you aren’t supposed to be an expert in Tutorial D! Be that as it may, the answer is yes for KEY and FOREIGN KEY constraints, no for other constraints. Note: There’s no particular reason why the answer shouldn’t be yes in the latter case too, if it were thought desirable; however, any temptation to intermingle (and thereby muddle, à la SQL) specification of the pertinent relation type and specification of such constraints should be firmly resisted. Also, we’d have to be careful over what it might mean for such a “base relvar” constraint if the base relvar to whose definition it’s attached happens to be empty (see the answer to Exercise 8.16 below).