% Understanding Databases: Concepts and Practice % S. W. Dietrich % Chapter 4 Relational Calculus: Domain Relational Calculus By Name % Practice Problems: Web Page % WEB PAGE % webpage (wID, wTitle, wURL, hits) primary key: wID % site (sID, sTitle, sURL) primary key: sID % graphic (gID, gName, gType, src, alt) primary key: gID % document (dID, dName, dType, dDescription, dDate, downloads, wID) primary key: dID % foreign key (wID) references webpage(wID) % internal (sourceID, targetID) primary key: sourceID, targetID % foreign key (sourceID) references webpage(wID) % foreign key (sourceID) references webpage(wID) % external (wID, sID, followed) primary key: wID, sID % foreign key (wID) references webpage(wID) % foreign key (sID) references site(sID) % displays (wID, gID) primary key: wID, gID % foreign key (wID) references webpage(wID) % foreign key (gID) references graphic(gID) % 1 Which pages contain a link to SQL ('sql') documents? % (wID, wTitle) drc1(wID: WID, wTitle: WTitle) <- webpage(wID: WID, wTitle: WTitle) and document(dType: 'sql', wID: WID); % ----------------------------------------------------------------------- % 2 Which pages display graphics having the name 'understandingbook'? % (wID, wTitle) drc2(wID: WID,wTitle: WTitle) <- (exists GID) (graphic(gID: GID, gName: 'understandingbook') and displays(wID: WID, gID: GID) and webpage(wID: WID, wTitle: WTitle) ); %------------------------------------------------------------------------ % 3 Which pages do not display any graphics? % (wID, wTitle) drc3(wID: WID,wTitle: WTitle) <- webpage(wID: WID,wTitle: WTitle) and not displays(wID: WID); %------------------------------------------------------------------------ % 4 Which pages display 'jpg' graphics but not 'gif' graphics? % (wID, wTitle) jpgPages(wID: WID) <- (exists GID) (graphic(gID: GID, gType: 'jpg') and displays(wID: WID, gID: GID) ); gifPages(wID: WID) <- (exists GID) (graphic(gID: GID, gType: 'gif') and displays(wID: WID, gID: GID) ); drc4(wID: WID, wTitle: WTitle) <- webpage(wID: WID,wTitle: WTitle) and jpgPages(wID: WID) and not gifPages(wID: WID); %------------------------------------------------------------------------ % 5 Which pages contain more than one document? % (wID, wTitle) drc5(wID: WID, wTitle: WTitle) <- webpage(wID: WID, wTitle: WTitle) and (exists D1, D2) (document(dID: D1, wID: WID) and document(dID: D2, wID: WID) and D1 <> D2); %------------------------------------------------------------------------ % 6 Which pages contain only one link to an external web page? % (wID, wTitle) drc6(wID: WID,wTitle: WTitle) <- webpage(wID: WID,wTitle: WTitle) and (exists SID1)(external (wID: WID, sID: SID1) and not (exists SID2)(external (wID: WID, sID: SID2) and SID1 <> SID2)); %------------------------------------------------------------------------ % 7 Which pages have the most hits? % (wID, wTitle, hits) drc7(wID: WID,wTitle: WTitle, hits: Hits) <- webpage(wID: WID, wTitle: WTitle, hits: Hits) and not (exists BiggerHits) (webpage(hits: BiggerHits) and BiggerHits > Hits); %------------------------------------------------------------------------ % 8 Which pages display graphics of all graphic types currently stored in the database? % (wID, wTitle) drc8(wID: WID,wTitle: WTitle) <- webpage (wID: WID,wTitle: WTitle) and not (exists GType)(graphic(gType: GType) and not (exists G)(displays(wID: WID, gID: G) and graphic(gID: G, gType: GType))); %-----------------------------End Web Page Enterprise-------------------------------------------