Sei sulla pagina 1di 22

Database Management System (05106) BE (IT) (IT.

05106)

Sample Questions For (Chapter 7, 8, 9)

Chapter (7) Tuple Calculus

S( S#, SNAME, STATUS, CITY ) PRIMARY KEY ( S# ) P ( P#, PNAME, COLOR, WEIGHT, CITY ) PRIMARY KEY ( P# ) J ( J#, JNAME, CITY ) PRIMARY KEY ( J# ) SPJ ( S#, P#, J# ) PRIMARY KEY ( S#, P#, J# ) FOREIGN KEY ( S# ) REFERENCE S FOREIGN KEY ( P# ) REFERENCE P FOREIGN KEY ( J# ) REFERENCE J Using the Supplier-Part. Project tables as shown above, write relational tuple calculus expressions for the following operations. 1. (i) Get supplier names for suppliers who supply at least one red part. (5-Marks) (ii) Get supplier numbers for suppliers who supply at least all those parts supplied by supplier S2. (5-Marks) (iii) Get part numbers for parts supplied to any project by a supplier in the same city as that project. (5-Marks) (iv) Get all pairs of supplier numbers such that the two suppliers are collocated. (5-Marks) 2. (i) (ii) (iii) (iv) 3. (i) Get all supplier-number / part-number / project-number triples such that no two of the indicated supplier-part and project are collocated. (5-Marks) Get the total quantity of part P1 supplied by supplier S1. (5-Marks) Get supplier numbers for suppliers who supply the same part to all projects. (5-Marks) Get supplier-number / part-number pairs such that the indicated supplier does not supply does not supply the indicated part. (5-Marks)

Get project numbers for projects supplied with part P1 in an average quantity greater than the greatest quantity in which any part is supplied to project J1. (5-Marks) (ii) Get part numbers for parts supplied by a supplier in London to a project in London. (5-Marks) (iii) Get project numbers for projects supplied entirely by supplier S1. (5-Marks) (iv) Get all pairs of part numbers such that some supplier supplies both the indicated parts. (5-Marks)

4. (i) Get supplier names for suppliers who do not supply part P2. (5-Marks) (ii) Get project numbers for projects supplied with at least all parts available from supplier S1. (5-Marks)

(iii) Get part numbers of parts supplied to some project in an average quantity of more than 350. (5-Marks) (iv) Get supplier numbers for suppliers with a status lower than that of supplier S1. (5-Marks) Domain Calculus Use the tables from Question 1, Formulate the queries by using the domain calculus expressions for the following operations. 5.(i) (ii) Get supplier number for suppliers in Pairs with status > 20. (5-Marks) Get supplier names for suppliers who supply at least one part supplied by supplier S2. (5-Marks) (iii) Get project numbers for projects whose city is first in the alphabetic list of such cities. (5-Marks) (iv) Get project numbers for projects supplied by at least one supplier not in the same city. (5-Marks) Get all pairs of city names such that a supplier in the first city supplies a project in the second city. (5-Marks) Get part numbers for parts that are supplied either by a London supplier or to a London project. (5-Marks) Get all pairs of supplier numbers such that the two suppliers are collocated. (5-Marks) Get project numbers for projects using at least one part available from supplier S1. (5-Marks) Get part numbers for parts supplied to all project in London. (5-Marks) Get all supplier-number / part number / project-number triples such that the indicated supplier, part and project are not all collocated. (5-Marks) Get all shipments where the quantity is in the range 300 to 750 inclusive. (5-Marks) Get part numbers for parts that either weigh more than 16 pounds or are supplied by supplier S2 or both. (5-Marks)

6.(i) (ii) (iii) (iv) 7.(i) (ii) (iii) (iv) 8.(i) (ii)

Get supplier names for suppliers who supply all parts. (5-Marks) Get all supplier-number / part-number / project-number triples such that the indicated supplier, part and project are all colocated. (5-Marks) (iii) Get supplier names for suppliers who do not supply part P2. (5-Marks) (iv) Get full details for parts supplied by a supplier in London. (5-Marks)

Facilities Using the supplier-part. Project tables above, write the SQL facilities for the following operations. 9.(i) Get color and city for nonParis parts with weight greater than ten pounds. (5-Marks) (ii) Get the maximum and minimum quantity for part P2. (5-Marks)

(iii) For each part being supplied to a project, get the part number, the project number, and the corresponding total quantity. (5-Marks) (iv) Get the total quantity of part P1 supplied by supplier S1. (5-Marks) 10.(i) Get all combination of supplier and part information such that the supplier and part in question are colocated. (5-Marks) (ii) For each part supplied, get the part number and the total shipment quantity. (5-Marks) (iii) Get supplier numbers for suppliers with status less than the current maximum status in the S table. (5-Marks) (iv) Get supplier numbers for suppliers supplying some project with part P1 in a quantity greater than the average shipment quantity of part P1 for that project. (5-Marks) 11.(i) Get supplier names for suppliers who supply at least one red part. (ii) Get part numbers for parts supplied by more than one supplier. (iii) Get all cities in which at least one supplier, part, or project is located. (iv) Get supplier names for suppliers who supply all parts. (5-Marks) (5-Marks) (5-Marks) (5-Marks)

12.(i) Get supplier numbers for suppliers supplying at least one part supplied by at least one supplier who supplies at least one red part. (5-Marks) (ii) Get supplier names for suppliers who supply part P2. (5-Marks) (iii) Get all pairs of supplier numbers such that the two suppliers concerned are colocated. (5-Marks) (iv) Get supplier names for suppliers who do not supply part P2. (5-Marks)

Chapter (8) Intergrity 1.(a) (b) How many categories in the integrity constraint and explain them. (8-Marks) Let A and B be two relvars. State the candidate key(s) for each of the following. (12-Marks) (1) A{} (2) A TIMES B (3) A UNION B (4) A MINUS B (5) EXTEND A ADD exp AS Z (6) A SEMIJOIN B Write integrity constraints for the supplier-parts-projects database as follows: (20-Marks) (1) The only legal cities are London, Paris, Rome, Athens, Oslo, Stockholm, Madrid, and Amsterdam. (5-Marks)

2.

(2) 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 0 to 9999. (5-Marks) (3) All red parts must weigh less than 50 pounds. (5-Marks) (4) At most one supplier can be located in Athens at anyone time. (5-Marks) (5) Every London supplier must supply part P2. (5-Marks) 3. Education database contains information about an in house company education training scheme. For each training course, the database contains details of all prerequisite courses for that course and all offerings for that course; for each offering, it contains details of all teachers and all student enrollments for that offering. The database also contains information about employees. The relevant relvars as follows in outline: COURSE { COURSE#, TITLE } PREREQ { SUP-COURSE#, SUB-COURSE# } OFFERING { COURSE#, OFF#, OFFDATE, LOCATION } TEACHER { COURSE#, OFF#, EMP# } ENROLLMENT { COURSE#, OFF#, EMP#, GRADE } EMPLOYEE { EMP#, ENAME, JOB } The meaning of the PREREQ relvar is that the superior course (SUP-COURSE#) has the subordinate course (SUB-COURSE#) as an immediate prerequisite: The other should be self-explanatory. Draw a referential diagram for this database. Also give the corresponding database definition(i.e write an appropriate set of type and relvar definitions. (20-Marks)

4. (a) Write the operation that might course the applicable constraint to be violated. (10-Marks) (1) No shipment can have a quantity more than double the average of all such quantities. (2) Every project must be located in a city in which there is at least one supplier. (3) (4) (5) The average supplier status must be greater than 18. At least one red part must weigh less than 50 pounds. Supplier in London must supply more parts in total than suppliers in Paris. (10-Marks)

(b) Define the following terms. (1) reference (2) referential integrity (3) referential constraint (4) referencing (5) referenced 5.

Give SQL solutions to the following operations. (20-Marks) (1) No two project can be located in the same city. (2) The highest status supplier must not be located in the same city as the lowest status supplier.

(3) (4) 6.

Every project must be located in a city in which there is at least one supplier of that project. There must exist at least one red part.

Write the CREATE ASSERTION to the following operations. (10-Marks) (1) Every supplier has status at least five. (2-Marks) (2) Every part has a positive weight. (2-Marks) (3) All red parts must be stored in London. (2-Marks) (4) No shipment has a total weight (part weight times shipment quantity) greater than 20,000: (2-Marks) (5) No supplier with status less than 20 can supply any part in a quantity greater than 500 Define the following terms: (1) The Golden Rule (2) Extend Rule (3) Superkey Rule (4) Functional Dependency (5) Triggered Procedure (10-Marks) (2-Marks) (2-Marks) (2-Marks) (2-Marks) (2-Marks)

(b)

Chapter (9) Views 1. 2. What do you understand about view, explain with reasons? (20-Marks) (1) Define a view consisting of supplier numbers and part numbers for suppliers and parts that are not colocated. (5-Marks) (2) Define a view for suppliers in London. (5-Marks) (3) Define relvar SP of the suppliers and parts database as a view of relvar SPJ of the suppliers-parts-projects database. (5-Marks) (4) Define a view over the suppliers-parts-projects database consisting of all projects (project number and city attributes only) that are supplied by supplier S1 and use part P1. (5-Marks) Give SQL solutions to the following operations. (20-Marks) (1) Define a view consisting of supplier numbers and part numbers for suppliers and parts that are not colocated. (5-Marks) (2) Define a view for suppliers in London. (5-Marks) (3) Define relvar SP of the suppliers and parts database as a view of relvar SPJ of the suppliers parts projects database. (2-Marks)

3.

(4)

Define a view over the suppliers-parts-projects database consisting of all projects (project number and city attributes only) that are supplied by supplier S1 and use part P1. (5-Marks)

4.

Define a view to the following operation by using SQL facilities. (20-Marks) (1) Get supplier number, status and city for suppliers that status is greater than 15. (5-Marks) (2) Get full details for all parts that color is red. (5-Marks) (3) Get part numbers and the corresponding total quantity. (5-Marks) (4) Get all pairs of city names such that a supplier in the first city suppliers a project in the second city. (5-Marks) (5) Get part number, name, weight and city that weight is more than 12. (5-Marks)

Database Management system ( BE ) IT solution for ( chapter 7,8,9 ) ( IT. 05106)

1 ( i ) SX.SNAME WHERE EX15TS SPJX ( ex15T5 PX ( SX.S# = SPJX.S# AND SPJX.P# = PX.P# AND PX.COLOR = COLOR = COLOR ( READ)))

(ii) SX.SNAME WHERE EX1STS 5PJX ( EXISTS SPJY ( SX.S# = SPJX.S# AND SPJ.5# = S PJY.P# AND SPJY.S# = S # ( S2)))

( iii) SPJX.P# WHERE EXISTS SX ( EXISTS JX (SX.CITY = JX. CITY AND SPJX.S# = SX.S# AND SPJX. J# = JX .J# ))

( iv)

( SX.S# AS SA ,SY.S# AS SB ) WHERE SX.CITY = SY.CITY AND SX. S# < SY.S>

2. (i)

(SX.S#, PX.P#, JX.J#) WHERE SX.CITY AND PX.CITY AND SX.CITY

PX.CITY

JX.CITY JX.CITY

(ii)

SUM ( SPJX WHERE SPJX.S# = S# ( S1) AND SPJX .P# = P# ( P1) ,QTY ) AS Q

(iii) SX.S# WHER EX EXISTS PX ( FORALL JX ( EXISTS SPJX ( SPJX.S# = SX. = SX.S# AND SPJX.P# = PX. P# AND SPJX.J# = JX.J#)))

(iv) ( PX.P# , SX.S# ) WHERE NOT EXISTS SPJ X ( SPJX.S# = SX.S# AND SPJX.P# = PX.P#)

3.( i ) SPJX.J# WHERE SPJX.P# = p# (p1) and AVG ( SPJY WHERE SPJV.P# =p# ( p1) AND SPJX .j# = SPJV.J# ,QTY)> MAX ( SPJZ where SPJZ.J# = j # ( J1),QTY)

(ii)

SPJX.P# WHERE EXISTS SX ( EXISTS JX ( SX.S# = SPJX.S# AND SX.CITY = LANDON AND JX.J# = SPJX.J# AND JX.CITY = LANDON))

( iii)

JX.J# WHERE FORALL SPJX ( IF ( SPJX. S# = s# (s1) then (SPTX.JX = JX. J#)END IF) (SPJX.P# AS XP# , SPJV.P# as VP# WHERE ( SPJX.S# = SPJY.S# AND SPJX.P# < SPJY.P#)

(iv)

4. (i )SX.SNAME WHERE NOT EX15T5 SPJ ( SX .S# = SPJX.S3 AND SPJX.P3 = P3 ( P2)) (ii) JX.J# WHERE FORALL SPJP ( IF SPJY.S# ( S1) THEN EXISTS SPJZ ( SPJZ.J# = JX.J# AND SPJZ.P# = SPJY.P# ) END IF) SPJX.P# AVG ( SPJY WHERE SPJX.P# == SPJY.P# AND SPJX.J# = SPJY.J# ,QTY)>OTY C35 SX.S# WHERE EXISTS SY ( SY.S# = S# (S1) AND SX.STATUS < SY.STATUS)

(ii) (iii)

Domain calculus
5.(i) (ii) SX WHERE EXISTS X CS ( S#: SX ,CITY : Pairs ,STATUS X AND STATUS X>20) NAMEX WHERE EXISTS 8X EXISTS PX ( S ( S# :SX,SNAME.NAME X) AND SPJ ( S# : SX,P# : PX) AND SPJ(S#: S#(S2),P#:PX)) JX WHERE EXIST CITY X CJ ( J# :JX,CITY:CITYX) AND FORALL CITY ( IF J( CITY:CITY Y) THEN CITY Y CITY X END IF)) JX WHERE EXIST SX EXISTS CITY EXISTS CITY Y ( S ( S#:SX, CITY:CITY X)AND J (J# :JX,CITY:CITY Y) AND SPJ ( S#: SX.J # : JX) AND CITY X CITY Y)

(iii)

( iv)

6.(i )

( CITY X AS S CITY,CITY Y AS J CITY) WHERE EXISTS SX EXISTS JX (S ( S#:SX,CITY:CITY X) AND J ( J#:JX, CITY:CITY Y) AND SPJ ( S#:SX,J#:JX))

(ii )

PX WHERE EXISTS SX ( SPJ ( S#:SX,P#:PX)AND S( S#:SX,CITY:LONDON)) OR EXIST JX ( SPJ ( P#:PX,J#:JX)AND J( J#:JX,CITY:LONDON)) (SX AS SA,SY AS SB) WHERE EXISTS CITY X S ( S#: SX,CITY: CITY X) AND S(S#:SY,CITY :CITY X) AND SX<SY. JX WHERE EXISTS PX ( SPJ CS#:S# ( S1) .P# :PX,J#:JX ) AND SPJ CP#:PX,J# :JX)) PX WHERE P ( P#:PX)AND FORALL JX( IF J(J#:JX,CITY:LONDON) THEN SPJ ( J#:JX,P#:PX) END IF) (SX.PX,JX) WHERE EXISTS CITYX EXISTS CITY Y EXISTS CITY Z ( S ( S#:SX,CITY:CITY X) AND P(P#:PX,CITY :CITY Y)AND J (J#:JX,CITY :CITY Z)AND CCITYX CITY Y OR CITY Y CITYZ OR CITY Z CITY X)) ( SX,PX,JX,QTYX) WHERE SPJ ( S#:SX,P#:PX,J#:JX,QTY:QTY X) AND QTY X QTY ( 300) AND QTY X QTY ( 750) PX WHERE EXISTS WEIGHT X ( P CP#:PX,WEIGHT X) AND WEIGHT X> WEIGHT (16.0) OR SPJ (S#:S#(S2),P#:PX)) NAMEX WHERE BEXISTS SX(S(S#:SX,SNAME:NAME X) AND FORALL PX( IF P(P#:PX) TYHEN SPJ (S#:SX,P#:PX) END IF)) ( SX,PX,JX) WHERE EXISTS CITY X (S(S#:SX,CITY:CITY X)AND P(P#:PX,CITY:CITY X)_AND J( j# :JX, CITY:CITY X) )

(iii)

(iii)

7.(i)

(ii)

(iii)

(iv)

8 (i)

8.(ii)

(iii) (iv) 9.(i)

NAME WHERE EXISTS SX ( S ( S#:SX,SNAME :NAME X) AND NOT SPJ ( S#:SX,P#:P#(P2)) PX WHERE EXISTS SX (S ( S#:SX,CITY :LONDON)AND SPJ ( S#:SX,P#:PX)) SELECT P.COLOR,P.CITY FROM P WHERE P.CITY< > PARIS AND P. WEIGHT > 10.0; SELECT MAX (SPJ.QTY)ASQ,MIN(SPJ.QTY) ASY FROM SPJ WHERE SPJ.PH = P2; SELECT SPJ.P#,SPJ.J#,SUM (SPJ.QTY) AS Q FROM SM GROUP BY SPJ.P# ,SPJ .j#; SELECT SUM ( SPJ.QTY) AS Q FROME SPJ WHERE SPJ.P# = P1; AND SPJ .S# = S1;

( ii )

(iii)

(iv)

10.(i) SELECT SX,PX FORME S,P WHERE S.CITY = P. CITY; (ii) SELECT SPJ.P# , SUM ( SPJ.QTY) AS Q FROME SPJ GROUP BY SPJ.P#; SELECT S.S# FROME S WHERE S.STATCIS< ( SELECT MAX CS.STATUS) FROME S); (iv) SELECT SPJX.S# FROME SPJ AS SPJX WHERE SPJX.P# = P1 AND SPJX.QTY> ( SELECT AVG ( SPJ.QTY) FROM SPJ AS SPJY WHERE SPJY.P# = P1 AND SPJX.J# = SPJY.J#);

(iii)

11.(i) SELECT DISTINCT S.SNAME FROME S,SPJ,P WHERE SPJ,P# = P.P# AND SPJ.S# = S.S# AND P.COLOR= PED; (ii) SELECT SPJ .P# FROM SPJ GROUP SPJ.P# HAVING COUNT ( SPJ.S#)>1; SELECT S.CITY FROM S CINION SELECT P.CITY FROM P CINION SELECT J.CITY FROM J; SELECT DISTINCT S.SAME FROM S WHERE NOT EXISTS ( SELECTP.* FROM P WHERE NOT EXISTS ( SELECT SPJ.* FROM SPJ WHERE SPJ.SH.S.S# AND SPJ.P# = P.P#));

(iii)

(iv)

12.(i) SELECT DISTINCT SPJX.S# FROM SPJ AS SPJX,SPJ,SPJ AS SPJY,SPJ AS SPJZ,P WHERE SPJX.P# = SPJY.P# AND SPJY.S# = SPJZ.S# AND SPJZ.P# = P. P# AND P.COLOR = RED;

(ii)

SELECT DISTNCT S.SNAME FROM S WHERE EXISTS ( SELECT SPJ.* FROM SPJ WHERE SPJ.P# = P2 AND SPJ.S# = S.S #);

(iii)

SELECT A.S# AS SA, B.S# AS SB FROM S AS A, S AS B WHERE A.CITY = B. CITY AND A.S# < B. S#; SELECT DISTINCT S.SNAME FROM S WHERE NOT EXISTS ( SELECT SPJ.* FROM SPJ WHERE SPJ.P# = P2 AND SPJ.S# = S. S#);

( iv)

CHAPTER (8) (Solutions) 1.(a) There are four categories in the integrity constraint. A type constraint specifies the legal values for a given type. Type to mean a scalar type specifically. Relation type are subject to type constraints too, of course, but those constraints are basically just a logical consequence of the type constraints that apply to the scalar types in terms of which those relation types are (ultimately) defined. An attribute constraint specifies the legal values for a given attribute. A relvar constraint specifies the legal values for a given relvar. A database constraint specifies the legal values for a given database. 1.(b)(1) A {} If the projection includes any candidate key K of A, then K is a candidate key for the projection. Otherwise the only candidate key is the combination of all attributes of the projection. (2) A Times B Every combination K of a candidate key KA of A and a candidate key KB of B is a candidate key for the product A Times B. (3) A UNION B The only candidate key for the union A UNION B is the combination of all attributes. (4) A MINUS B Every candidate key of A is a candidate key for the (5) EXTEND A ADD exp AS Z The candidate keys for an arbitrary extension of A are the same as the candidate keys of A. (6) A SEMIJOIN B Every candidate key of A is a candidate key for the semi join A SEMIJOIN B.

2. (1)

TYPE CITY POSSREP (CHAR) CONSTRAINT THE-CITY (CITY) = London OR THE-CITY (CITY) = Paris OR THE-CITY (CITY) = Rome OR THE-CITY (CITY) = Athens OR THE-CITY (CITY) = Oslo OR THE-CITY (CITY) = Stockholm OR THE-CITY (CITY) = Madrid OR THE-CITY (CITY) = Amsterdam;

(2) TYPE S# POSSREP (CHAR) CONSTRAINT SUBSTR (THE S# (S#), 1, 1.) = S AND CAST-AS-INTEGER (SUBSTR (THE S# (S#), 2) 0 AND CAST-AS-INTEGER (SUBSTR (THE S# (S#), 2) 9999; (3) CONSTRAINT M NOT (IS EMPTY (P WHERE (COLOR = COLOR (Red) AND WEIGHT < WEIGHT (50.0))); (4) CONSTRAINT E COUNT (S WHERE CITY = Athens) 1; (5) CONSTRAINT L IS-EMPTY ( ( S WHERE CITY = London) {S#} MINUS ( SPJ WHERE P# = P# (P2) ) {S#}); 3. TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE COURSE# TITLE OFF# OFFDATE CITY EMP# NAME JOB GRADE POSSREP POSSREP POSSREP POSSREP POSSREP POSSREP POSSREP POSSREP POSSREP (CHAR); (CHAR); (CHAR); (CHAR); (CHAR); (CHAR); (CHAR); (CHAR); (CHAR);

VAR COURSE BASE RELATION { COURSE# COURSE #, TITLE TITLE } PRIMARY KEY { COURSE # }; VAR PREREQ BASE RELATION { SUP-COURSE# COURSE#, SUB-COURSE# COURSE# } PRIMARY KEY { SUP-COURSE#, SUB COURSE# } FOREIGN KEY { RENAME SUP-COURSE# AS COURSE# } ` REFETENCES COURSE ON DELETE CASCADE ON UPDATE CASCADE

FOREIGN KEY { RENAME SUB-COURSE# AS COURSE# } ` REFETENCES COURSE ON DELETE CASCADE ON UPDATE CASCADE; VAR OFFERING BASE RELATION { COURSE# COURSE#, OFF# OFF#, OFFDATE OFFDATE, LOCATION CITY } PRIMARY KEY { COURSE# , OFF# } FOREIGN KEY { COURSE# } REFERENCES COURSE ON DELETE CASCADE ON UPDATE CASCADE; VAR EMPLOYEE BASE RELATION { EMP# EMP#, ENAME NAME, JOB JOB } PRIMARY KEY { EMP# }; VAR TEACHER BASE RELATION { COURSE# COURSE#, OFF# OFF#, EMP# EMP# } PRIMARY KEY { COURSE# , OFF# , EMP# } FOREIGN KEY { COURSE# , OFF# } REFERENCES OFFERING ON DELETE CASCADE ON UPDATE CASCADE FOREIGN KEY { EMP# } REFERENCES EMPLOYEE ON DELETE CASCADE ON UPDATE CASCADE; VAR ENROUMENT BASE RELATION ENROLLEMNT { COURSE# COURSE#, OFF# OFF#, EMP# EMP#, GRADE GRADE } PRIMARY KEY { COURSE# , OFF# , EMP# } FOREIGN KEY { COURSE# , OFF# } REFERENCES OFFERING ON DELETE CASCADE ON UPDATE CASCADE FOREIGN KEY { EMP# } REFERENCES EMPLOYEE ON DELETE CASCADE ON UPDATE CASCADE;

PREREQ SUP-COURSE# COURSE COURSE# COURSE,OFF# TEACHER OFFERING COURSE#, OFF# ENROLLMENT SUB-COURSE#

EMPLOYEE EMP# Fig: Re 4.(a) (1) INSERT or DELETE on SPJ, UPDATE on shipment QTY. (2) INSERT or J, DELETE on S, UPDATE on supplier or project CITY. (3) INSERT or DELETE on S, UPDATE on supplier STATUS. (4) INSERT or DELETE on P, UPDATE on part WEIGHT. (5) INSERT or DELETE on S or SPJ, UPDATE on supplier CITY or shipment S# Or P# or QTY. (b) (1) reference A foreign key value represents a reference to the topple containing the matching candidate key value. (2) Referential integrity The problem of ensuring that the database does not include any invalid foreign key values is therefore known as the referential integrity problem. (3) Referential constraint The constraint that values of a given foreign key must match values of the corresponding candidate key is known as a referential constraint. (4) Referencing The relvar that contains the foreign key as the referencing relvar. (5) referenced The relvar that contains the corresponding candidate key as the referenced relvar. 5. (1) CRATE ASSERTION SQL-D CHECK EMP#

( NOT EXISTS ( SELECT * FROM J JX WHERE EXISTS ( SELECT * FROM J JX WHERE ( JX.J# <> JY.J# AND JX.CITY = JY.CITY ) ) ) ); (2) CREATE ASSERTION SQL-G CHECK ( NOT EXISTS ( SELECT * FROM S SX WHERE NOT EXISTS ( SELECT * FROM S SY WHERE SX.STATUS = ( SELECT MAX (S.STATUS) FROM S ) AND SY.STATUS = ( SELECT MIN (S.STATUS) FROM S ) AND SX.STATUS <> SY.STATUS AND SX.CITY = SY.CITY ) ) ); (3) CREATE ASSERTION SQL-J CHECK ( NOT EXISTS ( SELECT * FROM P) OR EXISTS ( SELECT * FROM P WHERE P.WLOR = Red ) ); 6.(a) (1) CREATE ASSERTION JC 13 CHECK ( C SELECT MIN (S.STATUS) FROM S ) > 4 ); (2) CREATE ASSERTION IC 18 CHECK ( NOT EXISTS ( SELECT * FROM P WHERE NOT ( P.WEIGHT > 0.0 ) ) ); (3) CREATE ASSERTION IC 99 CHECK ( NOT EXISTS ( SELECT * FROM P WHERE P.COLOR = Red AND P.CITY <> London ) ); (4) CREATE ASSERTION IC 46 CHECK ( NOT EXISTS ( SELECT * FROM P, SP WHERE P.P# = SP.P# AND ( P.WEIGHT * SP.QTY ) > 20000.0 ) ); (5) CREATE ASSERTION IC 95 CHECK ( NOT EXISTS ( SELECT * FROM P, SP WHERE S.STATUS < 20 AND S.S# = SP.S# AND SP.QTY > 500 ) ); 6.(a) (1) CREATE ASSERTION JC 13 CHECK ( ( SELECT MIN (S.STATUS) FROM S ) > 4 );

(2) CREATE ASSERTION IC 18 CHECK ( NOT EXISTS ( SELECT * FROM P WHERE NOT ( P.WEIGHT > 0.0 ) ) ); (3) CREATE ASSERTION IC 99 CHECK ( NOT EXISTS ( SELECT * FROM P WHERE P.COLOR = Red AND P.CITY <> London ) ); (4) CREATE ASSERTION IC 46 CHECK ( NOT EXISTS ( SELECT * FROM P, SP WHERE P.P# = SP.P# AND ( P.WEIGHT * SP.QTY ) > 20000.0 ) ); (5) CREATE ASSERTION IC 95 CHECK ( NOT EXISTS ( SELECT * FROM S, SP WHERE S.STATUS < 20 AND S.S# = SP.S# AND SP.QTY > 500 ) ); 6.(b) (1) The Golden Rule No update operation must ever be allowed to leave an relvar in a state that violates its own predicate. (2) Extended Golden Rule No update operation must ever be allowed to leave any relvar in a state that violates its own predicate. Likewise, no update transaction must ever be allowed to leave the database in a state that violates its own predicate. (3) Superkey A superset of a candidate key is a superkey. A superkey has the uniqueness property but not necessarily the irreducibility property. (4) Functional Dependency If SK is a superkey for relvar R and A is an attribute of R, then the functional dependency SK A necessarily holds true in R. A superkey to be a subset SK of the attributes of R such that the functional dependency SK A holds true for all attributes A of R. (5) Triggered Procedure A triggered procedure is a procedure that is involves automatically on the occurrence of some specified event or trigger condition. Chapter (9)

Views Solutions 1. There are many reasons why view support is desirable. Views provide automatic security for hidden data (2-Marks) Views provide a shorthand or macro capability (2-Marks) Consider the query Get cities that store parts that are available from some supplier in London. Assume view CITY-PAIR is given. (CITY-PAIR WHERE SCITY = London) {PCITY} (4-Marks) Without the view, the query is much more complex: ( ( ( S RENAME CITY AS SCITY ) JOIN SP JOIN ( P RENAME CITY AS PCITY ) ) WHERE SCITY = London ) {PCITY} (4-Marks) There is a strong analogy here with macros in a programming language system. Thus, view in a database system play a role somewhat analogous to that of macro in a programming language system, and the well-known advantages and benefits of macro apply directly to views as well, mutatis mutandis. (3-Marks) Views allow the same data to be seen by different users in different users in different ways at the same time. (2-Marks) Views can provide logical data independence. This is one of the most important points of all logical data independence (a1) be defined as the immunity of users and user programs to change in the logical structure of the database. (3-Marks) VAR NON COLOCATED VIEW ( S TIMES P ) { S#, P# } MINUS ( S JOIN P ) { S#, P# }; VAR LONDON SUPPLIER VIEW ( S WHERE CITY = London ) { ALL BUT CITY }; VAR SP VIEW SUMMARIZE SPJ PPE SPJ { S#, P# } ADD SUM {QTY} AS QTY; VAR JC VIEW ( ( SPT WHERE S# = S# ( S1 ) ) { J# } JOIN ( SPT WHERE P# = P# ( P1 ) ) { J# } JOIN J { J#, CITY } CREATE VIEW NON-COLOCATED

2.(1)

(2) (3)

(4)

3.(1)

AS SELECT FROM WHERE (2)

S.S#, P.P# S, P S.CITY <> P.CITY;

CREATE VIEW LONDON-SUPPLIER AS SELECT S.S#, S.SNAME, S.STATUS FROM S.CITY = London; CREATE VIEW SP AS SELECT SPJ.S#, SPJ.P#, SUM (SPJ.QTY) AS QTY FROM SPJ GROUP BY SPT.S#, SPJ.J#; CREATE VIEW JC AS SELECT FROM WHERE

(3)

(4)

J.J#, J.CITY J J.J# IN ( SELECT SPJ.J# FROM` SPJ WHERE SPJ.S# = S1 ) AND J.J# IN ( SELECT SPJ.J# FROM SPJ WHERE SPJ.P# = P1 ); 4.(1) CREATE VIEW GOOD-SUPPLIER AS SELECT S.S#, S.STATUS, S.CITY FROM S WHERE S.STATUS > 15 WITH CHECK OPTION; (2) CREATE VIEW REDPART AS SELECT P.P#, P.NAME, P.WEIGHT AS WT, P.CITY FROM P WHERE P.COLOR = Red WITH CHECK OPTION; (3) CREATE VIEW CITY PAIR AS SELECT DISTINCT S.CITY AS SCITY, P.CITY AS PCITY FROM WHERE AND (4) CREATE VIEW HEAVY REDPART AS SELECT RP.P#, RP.PNAME, RP.WT, RP.CITY FROM REDPART AS RP WHERE RP.WT > 12.0 WITH CHECK OPTION;