Database Exercise 6.5.2 write the following database modifications, based on the
ID: 3602448 • Letter: D
Question
Database Exercise 6.5.2 write the following database modifications, based on the database schema Classes(class, type, country, numGuns, bore, displacement) Ships(name, class, launched) Battles(name, date) Outcomes(ship, battle, result) a) Modify the Classes relation so that gun bores are measured in centimeters (1 inch = 2.54 centimeters) and displacement are measured in metric tons (1 metric ton = 1.15 tons). b) Delete all classes with two or fewer ships. C) Each class is required to have a ship with the class name launched the same year the first ship in the class was launched. Add this fact to the database, for all the classes that do not satisfy it. I am using MySQL and these are database querys
Explanation / Answer
a)
UPDATE Classes
SET bore = bore*2.5, displacement = displacement/1.1;
sqlite> select * from classes;
Kongo|bc|Japan|8|35|29090.9090909091
Revenge|bb|Gt. Britain|8|37.5|26363.6363636364
Vittorio Veneto|bb|Italy||37.5|37272.7272727273
b)
DELETE FROM Classes
WHERE class IN (
SELECT class
FROM Classes NATURAL LEFT OUTER JOIN Ships
GROUP BY class
HAVING COUNT(name)<3);
Remain:
select * from classes;
Kongo|bc|Japan|8|14|32000
Revenge|bb|Gt. Britain|8|15|29000
Vittorio Veneto|bb|Italy||15|41000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.