Starting from:
$30

$24

Assignment 1: Relational Model and Relational Algebra Solution

PART 1 (20 points): SQL CREATE TABLE




Database 1: A computer database schema consists of four relations, whose schemas are:




Product (maker, model, type)

PC (model, speed, ram, hdisk, price)

Laptop (model, speed, ram, hdisk, screen, price)




Printer (model, color, type, price)




Key attributes are underlined. The Product relation gives the manufacturer, model number and type (PC, laptop, or printer) of various products. The PC relation gives for each model number the CPU speed (in GHz), memory size (in MB), hard disk size (in GB), and the price. The Laptop relation is similar, except that the screen size (in inches) is also included. The Printer relation records for each printer model whether the printer outputs color or not, the printer type (laser or inkjet, etc.), and the price.




Database 2: Here is another database schema concerning World War II capital ships. It involves the following relations:




Classes (class, type, country, guns, bore, displacement)

Ships (name, class, launched)




Battles (name, bdate)

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 relation Classes records the name of the 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 Outcomes gives the result (sunk, damaged, or ok) for each ship in each battle.




Database 3: Assume a book store has a mail-order database with the following schema of relations:

(Primary keys are underlined. Meaning of each attribute is self-explanatory by its name.)




Employees (Eno, Ename, Hire_Date); Books (Isbn, Bname, Quantity, Price); Customers (Cno, Cname, Street, Zip, Phone); Orders (Ono, Cno, Eno, Received, Shipped); Orderline (Ono, Isbn, Qty); Zipcodes (Zip, City, State);




Write a SQL CREATE TABLE statement (with proper data types for attributes and proper primary key) for each of the above relations.




PART 2 (30 points): Relational Algebra




For the computer database, write expressions of relational algebra to answer the following queries:

What PC models have a speed of at least 3.00?
Which manufacturers make laptops with a hard disk of at least 100GB?
Find the model number and price of all products (of any type) made by manufacturer B.
Find the model numbers of all color laser printers.
Find those manufacturers that sell Laptops, but not PC ’s.
Find those hard-disk sizes that occur in two or more PC’s.



Find those pairs of PC models that have both the same speed and RAM. A pair should be listed only once; e.g., list (i, j) but not (j, i).



Find those manufacturers of at least two different computers (PC’s or laptops) with speeds of at least 2.80.
Find the manufacturers of PC ’s with at least three different speeds.
Find the manufacturers who sell at least three different models of PC.



For the battleship database, write expressions of relational algebra to answer the following queries:




Give the class names and countries of the classes that carried guns of at least 16-inch bore.
List all ships that belong to USA.
Find the ships launched prior to 1921.
Find the ships sunk in the battle of the Denmark Strait.



The treaty of Washington in 1921 prohibited capital ships heavier than 35,000 tons. List the ships that violated the treaty of Washington.



List the name, displacement, and number of guns of the ships engaged in the battle of Guadalcanal.



List all the capital ships mentioned in the database. (Remember that all these ships may not appear in the Ships relation.)
Find the classes that had only one ship as a member of that class.
Find those countries that had both battleships and battlecruisers.
Find those ships that were damaged in one battle, but later fought in another.



For the bookstore database, write expressions of relational algebra to answer the following queries:




list customers (cnd, name) the zip of whose address is 49008.
list customers (cno’s and names) who live in Michigan.
list employees (names) who have customers in Michigan.
list employees (names) who have both 49008-zipcode customers and 49009-zipcode customers.
list customers (names) who've ordered books through an employee named 'Jones'.
list customers (names) who've NOT ordered the book "Database".
all possible pairs of books (Bname’s). (A pair should be listed only once).



all possible pairs of books (Bname’s) where the first has a price of 24.99 and the second has a price of 19.99.



customers (names) who ordered at least one book that customer #1111 ordered.



customers (names) who ordered all the books as customer #11111 ordered (although, they may have ordered additional books).



Prepare your answers in a single file using a word processor and submit the file to the WMU e-learning.

More products