Exercise 6-1.Define the terms type constraint and database constraint. When are such constraints checked? What happens if the check fails? Exercise 6-2State The Golden Rule. Exercise 6-3What do you understand by the terms attribute constraint; tuple constraint; relvar constraint; "the" database constraint; "the" relvar constraint; single-relvar constraint; multi-relvar constraint? Exercise 6-4Distinguish between possible and physical representations. Exercise 6-5Explain as carefully as you can (a) what a selector is and (b) what a THE_ operator is. Exercise 6-6Suppose the only legal CITY values are London, Paris, Rome, Athens, Oslo, Stockholm, Madrid, and Amsterdam. Define a type called CITY that satisfies this constraint. Is there a way to impose the same constraint without an explicit CITY type? If so, compare and contrast the different approaches. Exercise 6-7Throughout this book I assume that SNO is a user-defined type. Give a definition for this type. Assume that the only legal supplier numbers are ones that can be represented by a character string of at least two characters, of which the first is an "S" and the remainder denote a decimal integer in the range 1 to 9999. Exercise 6-8A line segment is a straight line connecting two points in the euclidean plane. Give a corresponding type definition. Exercise 6-9Can you think of a type for which we might want to specify two different possreps? If there are two or more possreps for the same type, does it make sense for each to include a type constraint? Exercise 6-10Can you think of an example of a type for which different possreps have different numbers of components? Exercise 6-11Which operations might cause constraints C1-C8 from the body of the chapter to be violated? Exercise 6-12Constraint C1 (for example) had the property that it could be checked for a given tuple by examining just that tuple in isolation; constraint C4 (for example) did not. What is it, formally, that accounts for this difference? What's the pragmatic significance, if any, of this difference? Exercise 6-13Can you give a Tutorial D database constraint that's exactly equivalent to the specification KEY{SNO} for relvar S? Exercise 6-14Give an SQL formulation of constraint C7 from the body of the chapter. Exercise 6-15Give an SQL formulation of constraint C8 from the body of the chapter. Exercise 6-16Using Tutorial D and/or SQL, write constraints for the suppliers-and-parts database to express the following requirements:
In each case, state which operations might cause the constraint to be violated. Exercise 6-17In a footnote in the section "Constraints and Predicates," I said that if the values S1 and London appeared together in some tuple, then it might mean (among many other possible interpretations) that supplier S1 doesn't have an office in London. Actually, this particular interpretation is extremely unlikely. Why? (Hint: Remember the Closed World Assumption.) Exercise 6-18Suppose no "cascade delete" rule is stated declaratively for suppliers and shipments. Write a Tutorial D statement that will delete some specified supplier and all shipments for that supplier in a single operation. Exercise 6-19Using the syntax sketched for transition constraints in the section "Miscellaneous Issues," write transition constraints to express the following requirements:
Exercise 6-20Distinguish between correctness and consistency. Exercise 6-21Do you think the following is or should be a valid Tutorial D TYPE statement? TYPE TTT POSSREP { ... CONSTRAINT FALSE } ; Exercise 6-22Do you think the following is or should be a valid Tutorial D CONSTRAINT statement? CONSTRAINT FFF FALSE ; Exercise 6-23Investigate any SQL product that might be available to you. What semantic optimization does it support, if any? Exercise 6-24Why do you think SQL fails to support type constraints? What are the consequences of this state of affairs? Exercise 6-25The discussion in this chapter of types in general, and type constraints in particular, tacitly assumed that types were all (a) scalar and (b) user-defined. Do the concepts discussed apply equally well to nonscalar types and/or system-defined types? |