Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Algebra (Continued)

Similar presentations


Presentation on theme: "Relational Algebra (Continued)"— Presentation transcript:

1 Relational Algebra (Continued)
Database Management COP4540, SCS, FIU

2 classes (class, type, country, numGuns, bore, displacement)
Here is a running example concerning World War II capital ships. It involved the following relations: classes (class, type, country, numGuns, bore, displacement) ships (name, class, launched) battles(name, date) outcomes (ship, battle, result) Ships are built in “classes” from the same design, and the class is usually named for the first ship of that class, the type (bb for battleship or bc for battlecruiser), the country that built the ship, the number of main guns, the bore (diameter of the gun barrel, in inches) of the main guns, and the displacement (weight in tons). Relation Ships records the name of the ship, the name of its class, and the year in which the ship was launched. Relation Battles gives the name and date of battles involving these ships, and relation Outcome gives the result (sunk, damaged, or OK) for each ship in each battle. Query Requests: a) Give the class names and countries of the classes that carried guns of at least 16-inch bore. b) Find the ships launched prior to 1921 c) Find the ships sunk in the battle of the North Atlantic d) The treaty of Washington in 1921 prohibited capital ships heavier than 35,000 tons. List the ships that violated the treaty of Washington Database Management COP4540, SCS, FIU

3 classes (class, type, country, numGuns, bore, displacement)
Here is a running example concerning World War II capital ships. It involved the following relations: classes (class, type, country, numGuns, bore, displacement) ships (name, class, launched) battles(name, date) outcomes (ship, battle, result) Ships are built in “classes” from the same design, and the class is usually named for the first ship of that class, the type (bb for battleship or bc for battlecruiser), the country that built the ship, the number of main guns, the bore (diameter of the gun barrel, in inches) of the main guns, and the displacement (weight in tons). Relation Ships records the name of the ship, the name of its class, and the year in which the ship was launched. Relation Battles gives the name and date of battles involving these ships, and relation Outcome gives the result (sunk, damaged, or OK) for each ship in each battle. Query Requests: e) List the name, displacement, and number of guns of the ships engaged in the battle of Guadalcanal f) List all the capital ships mentioned in the database. Database Management COP4540, SCS, FIU

4 classes (class, type, country, numGuns, bore, displacement)
Here is a running example concerning World War II capital ships. It involved the following relations: classes (class, type, country, numGuns, bore, displacement) ships (name, class, launched) battles(name, date) outcomes (ship, battle, result) Ships are built in “classes” from the same design, and the class is usually named for the first ship of that class, the type (bb for battleship or bc for battlecruiser), the country that built the ship, the number of main guns, the bore (diameter of the gun barrel, in inches) of the main guns, and the displacement (weight in tons). Relation Ships records the name of the ship, the name of its class, and the year in which the ship was launched. Relation Battles gives the name and date of battles involving these ships, and relation Outcome gives the result (sunk, damaged, or OK) for each ship in each battle. Query Requests: g) Find the classes that had only one ship as a member of that class h) Find those countries that had both battleships and battlecruisers i) find those ships that “lived to fight another day”; they were damaged in one battle, but later fought in another. Database Management COP4540, SCS, FIU

5 Answers a) Πclass, country (bore >= 16(classes))
b) launched < 1921(ships) Database Management COP4540, SCS, FIU

6 Answers c) Πship ( result = ‘sunk’ .and. battle = ‘North Atlantic’ (outcomes)) Πship ( result = ‘sunk’ (outcomes)   battle = ‘North Atlantic’ (outcomes)) Πship ( result = ‘sunk’ (  battle = ‘North Atlantic’ (outcomes))) Πship ( battle = ‘North Atlantic (  result = ‘sunk’ (outcomes))) Database Management COP4540, SCS, FIU

7 Answers d) Πname (launched > 1921(ships) displacement > 35,000 (classes)) Πname(Πname, class (launched > 1921(ships)) Πclass(displacement > 35,000 (classes)) e) Πname, displacement, numGuns( classes (ships name = ship (battle = ‘Guadalcanal’ (outcomes)))) Database Management COP4540, SCS, FIU

8 Answers f) Πname (ships)
g) Πclass (classes) - Πclass (ships ships.class = ship2.class .and. ships.name <> ship2.name ρShip2 (ships)) Database Management COP4540, SCS, FIU

9 Answers h) Πcountry (type = ‘bb’ (classes))  Πcountry ( type = ‘bc’ (classes)) i) ΠR1.ship ( ( ρR1(result = ‘damaged’ ( outcomes) battle = name battles)) R1.ship = R2.ship .and. R1.date < R2.date ρR2(outcomes battle = name battles) ) Database Management COP4540, SCS, FIU


Download ppt "Relational Algebra (Continued)"

Similar presentations


Ads by Google