Explore BrainMass
Share

Five SQL queries explained

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

4.1) Consider the insurance database below, where the primary keys are underlines. Construct the following SQL queries for this relational database.

INSURANCE DATABASE

Person ( ss#, name, address)
Car (license, year, model)
Accident (data, driver, damage - amount)
Owns (ss#, license)
Log (license, date, driver)

I
a.) Find the total number of people whose cars were involved in accidents in 1989.

b.) Find the number of accidents in which the cars belonging to "John Smith" were involved.

c.) Add a new customer to the database.

d.) Delete the Mazda belonging to "John Smith".

e.) Add a new accident record for the Toyota belonging to "Jones".

© BrainMass Inc. brainmass.com March 21, 2019, 6:35 pm ad1c9bdddf
https://brainmass.com/computer-science/sql/five-sql-queries-explained-261890

Attachments

Solution Preview

This solution assumes that the "driver" in the Accident table is associated with the ssn in the Person table. This also uses generic SQL and doesn't rely on any database specific commands. One caveat here is that different databases handle date comparisons differently.
This solutions uses the most generic way of handling dates.

a.) Find the total number of people whose cars were involved in accidents in 1989.

SELECT count(*)
FROM Accident
WHERE (date >= 1/1/1989) AND (date <= 12/31/1989)

This query selects "count(*)" of all of the records in the Accident table where the date of the accident is in 1989.

b.) Find the number ...

Solution Summary

This solution creates five SQL queries and explains how they work.

$2.19