Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MYSQL databases The database: CREATE TABLE MoSpo_RaceCourse ( raceCourseName VARCHAR(30) PRIMARY KEY, raceCourseLocation VARCHAR(30), raceCourseLength DEC(5,3) UNSIGNED ); CREATE TABLE MoSpo_Race ( raceName VARCHAR(30), raceDate

MYSQL databases

image text in transcribedimage text in transcribedimage text in transcribed

The database:

CREATE TABLE MoSpo_RaceCourse ( raceCourseName VARCHAR(30) PRIMARY KEY, raceCourseLocation VARCHAR(30), raceCourseLength DEC(5,3) UNSIGNED );

CREATE TABLE MoSpo_Race ( raceName VARCHAR(30), raceDate DATE, raceTime TIME, raceVenue VARCHAR(30), raceLaps TINYINT UNSIGNED, PRIMARY KEY (raceName,raceDate), CONSTRAINT MoSpo_Race_Location FOREIGN KEY (raceVenue) REFERENCES MoSpo_RaceCourse(raceCourseName) );

CREATE TABLE MoSpo_Lap ( lapNo TINYINT UNSIGNED, lapRaceName VARCHAR(30), lapRaceDate DATE, CONSTRAINT MoSpo_Lap_Race FOREIGN KEY (lapRaceName,lapRaceDate) REFERENCES MoSpo_Race(raceName, raceDate), PRIMARY KEY(lapNo,lapRaceName,lapRaceDate) );

CREATE TABLE MoSpo_RacingTeam ( teamName VARCHAR(30) primary key, teamPostcode CHAR(9), teamStreet VARCHAR(30), teamHouseNo CHAR(4) );

CREATE TABLE MoSpo_Driver( driverId INTEGER UNSIGNED PRIMARY KEY, driverDOB DATE, driverLastname VARCHAR(30), driverFirstname VARCHAR(30), driverNationality VARCHAR(20), driverTeam VARCHAR(30), CONSTRAINT MoSpo_Driver_Team FOREIGN KEY (driverTeam) REFERENCES MoSpo_RacingTeam(teamName) );

CREATE TABLE MoSpo_Car( carId INTEGER UNSIGNED PRIMARY KEY, carMake VARCHAR(30), carTeam VARCHAR(30), CONSTRAINT MoSpo_Car_Team FOREIGN KEY (carTeam) REFERENCES MoSpo_RacingTeam(teamName) );

CREATE TABLE MoSpo_RaceEntry( raceEntryNumber TINYINT UNSIGNED, raceEntryRaceName VARCHAR(30), raceEntryRaceDate DATE, raceEntryDriverId INTEGER UNSIGNED NOT NULL, raceEntryCarId INTEGER UNSIGNED NOT NULL, raceEntryTyreType ENUM('soft','hard','wet','intermediate','medium','super-soft'), PRIMARY KEY (raceEntryNumber,raceEntryRaceName,raceEntryRaceDate), CONSTRAINT MoSpo_RaceEntry_Race FOREIGN KEY (raceEntryRaceName,raceEntryRaceDate) REFERENCES MoSpo_Race(raceName,raceDate), CONSTRAINT MoSpo_RaceEntry_Driver FOREIGN KEY (raceEntryDriverId) REFERENCES MoSpo_Driver(driverId), CONSTRAINT MoSpo_RaceEntry_Car FOREIGN KEY (raceEntryCarId) REFERENCES MoSpo_Car(carId) );

CREATE TABLE MoSpo_LapInfo ( lapInfoLapNo TINYINT UNSIGNED, lapInfoRaceName VARCHAR(30), lapInfoRaceDate DATE, lapInfoRaceNumber TINYINT UNSIGNED, lapInfoFuelConsumption DECIMAL(4,2), lapInfoTime INT UNSIGNED, -- milliseconds lapInfoCompleted TINYINT UNSIGNED NOT NULL DEFAULT 1, PRIMARY KEY (lapInfoLapNo, lapInfoRaceName, lapInfoRaceDate, lapInfoRaceNumber), CONSTRAINT MoSpo_LapInfo2_Lap FOREIGN KEY (lapInfoLapNo, lapInfoRaceName, lapInfoRaceDate) REFERENCES MoSpo_Lap(lapNo,lapRaceName,lapRaceDate), CONSTRAINT MoSpo_LapInfo2_Car FOREIGN KEY (lapInfoRaceNumber, lapInfoRaceName, lapInfoRaceDate) REFERENCES MoSpo_RaceEntry(raceEntryNumber, raceEntryRaceName,raceEntryRaceDate) );

CREATE TABLE MoSpo_PitStop ( pitstopLapNo TINYINT UNSIGNED, pitstopRaceName VARCHAR(30), pitstopRaceDate DATE, pitstopRaceNumber TINYINT UNSIGNED, pitstopDuration INT UNSIGNED, -- milliseconds pitstopChangedParts SET('front_wing','rear_wing','nose','steering','suspension','shock_absorber','tyre'), PRIMARY KEY (pitstopLapNo, pitstopRaceName, pitstopRaceDate, pitstopRaceNumber), CONSTRAINT MoSpo_PitStop2_Lap FOREIGN KEY (pitstopLapNo, pitstopRaceName, pitstopRaceDate) REFERENCES MoSpo_Lap(lapNo,lapRaceName,lapRaceDate), CONSTRAINT MoSpo_PitStop2_Car FOREIGN KEY (pitstopRaceNumber, pitstopRaceName, pitstopRaceDate) REFERENCES MoSpo_RaceEntry(raceEntryNumber, raceEntryRaceName,raceEntryRaceDate) );

You can use any sample data of your own. I only need the MYSQL statements

Specification A race has a name and must take place at a single race course at a specific date and at a specific starting time. A race has a certain num- ber of laps (around the race course) and a total length in miles. No two races of the same name take place on the same day. A race course has a unique name, a location, and a length in miles. For each driver, we keep the name, consisting of first and last name, nationality, date of birth and a unique driver identifier. Drivers always belong to a single racing team. We need to find out which driver drove which car in which race. We also need to store in which place they ar- rived at the finish (non-finishers are recorded as arrived in 0-th place). Drivers drive at most one car in a race but not all drivers do. There are no driver swaps during a race but at different races different drivers may be driving the same car. The type of tyres on the car at the start of the race is recorded as well as the car's racing number for that particular race. Cars have a unique identifier and must belong to a racing team. The make of the engine of a car is relevant too. Not every car is necessarily driven in a race. A car may complete a lap of a race in which case the lap time and fuel consumption are to be recorded. A car may have a pit stop during a lap in a race, in which case the duration of the pit stop and the items that have been changed during the pit stop (tyres, front nose, etc.) are recorded. A car may retire in a lap of a race, in which case the reason for the retirement is to be recorded. In all these cases, we need to know in which lap of which race this occurred. Important aspects of a racing team are its name and the address of the team's headquarter consisting of postcode, street name, house num- ber. Racing teams may be entered on the database before any drivers or cars are assigned to them. QUESTION 1 For any given care make m and time period t, let Retirements Ratem(t) be the total number of retirements of cars of make m divided by the total number of cars of make m taking part in a race during time t. In case no car of make m participated in racer during period t this number is undefined (NULL). For example, lett be the year 2000 and m = Porsche. Assume that in the year 2000 there were two races with Porsche cars involved. In the first race 2 cars of that make raced and 1 had a retirement. In the second race 3 cars of that make raced with 0 retirements. Therefore, we get that RetirementsRate Porsche(t) = { = 0.2. For a period t, let Average RetirementRate(t) be the average of re- tirement rates for period t across all makes m, i.e. the average of RetirementsRatem(t) ignoring undefined values, over all makes m. List for each car make m the retirement rate RetirementRatem(t) where t is the current year. Only select car makes m with a retirement rate above the average retirement rate across all makes for the same pe- riod t, i.e. where Retirement Ratem(t) > AverageRetirement Rate(t). The headings must look like this: carMake retirementRate QESTION 2 Write a stored function totalRace Time that, given a racing num- ber, the name of a race, and the date of a race, returns the total race time for the car specified by the racing number in the given race. If the given race does not exist, the routine should throw the error proce- dure Race does not exist. If the specified racing number did not take part in the existing race, the routine should throw an error procedure RaceEntry does not exist. In the case that not all required lap times for the existing) car in the (existing) race are available either until race finish or retirement, the routine should throw the error procedure Time ForAllLaps does not exist. If the existing) race was not completed by the (participating) car in the race due to retirement but all lap times were available until retire- ment, the routine must not throw an error but return null. Note that in those error cases the function must not return a string but produce an SQL error. The total race time should be returned as an integer denoting millisec- onds. Note that this stored routine has three arguments and you must declare them in the order given above. Specification A race has a name and must take place at a single race course at a specific date and at a specific starting time. A race has a certain num- ber of laps (around the race course) and a total length in miles. No two races of the same name take place on the same day. A race course has a unique name, a location, and a length in miles. For each driver, we keep the name, consisting of first and last name, nationality, date of birth and a unique driver identifier. Drivers always belong to a single racing team. We need to find out which driver drove which car in which race. We also need to store in which place they ar- rived at the finish (non-finishers are recorded as arrived in 0-th place). Drivers drive at most one car in a race but not all drivers do. There are no driver swaps during a race but at different races different drivers may be driving the same car. The type of tyres on the car at the start of the race is recorded as well as the car's racing number for that particular race. Cars have a unique identifier and must belong to a racing team. The make of the engine of a car is relevant too. Not every car is necessarily driven in a race. A car may complete a lap of a race in which case the lap time and fuel consumption are to be recorded. A car may have a pit stop during a lap in a race, in which case the duration of the pit stop and the items that have been changed during the pit stop (tyres, front nose, etc.) are recorded. A car may retire in a lap of a race, in which case the reason for the retirement is to be recorded. In all these cases, we need to know in which lap of which race this occurred. Important aspects of a racing team are its name and the address of the team's headquarter consisting of postcode, street name, house num- ber. Racing teams may be entered on the database before any drivers or cars are assigned to them. QUESTION 1 For any given care make m and time period t, let Retirements Ratem(t) be the total number of retirements of cars of make m divided by the total number of cars of make m taking part in a race during time t. In case no car of make m participated in racer during period t this number is undefined (NULL). For example, lett be the year 2000 and m = Porsche. Assume that in the year 2000 there were two races with Porsche cars involved. In the first race 2 cars of that make raced and 1 had a retirement. In the second race 3 cars of that make raced with 0 retirements. Therefore, we get that RetirementsRate Porsche(t) = { = 0.2. For a period t, let Average RetirementRate(t) be the average of re- tirement rates for period t across all makes m, i.e. the average of RetirementsRatem(t) ignoring undefined values, over all makes m. List for each car make m the retirement rate RetirementRatem(t) where t is the current year. Only select car makes m with a retirement rate above the average retirement rate across all makes for the same pe- riod t, i.e. where Retirement Ratem(t) > AverageRetirement Rate(t). The headings must look like this: carMake retirementRate QESTION 2 Write a stored function totalRace Time that, given a racing num- ber, the name of a race, and the date of a race, returns the total race time for the car specified by the racing number in the given race. If the given race does not exist, the routine should throw the error proce- dure Race does not exist. If the specified racing number did not take part in the existing race, the routine should throw an error procedure RaceEntry does not exist. In the case that not all required lap times for the existing) car in the (existing) race are available either until race finish or retirement, the routine should throw the error procedure Time ForAllLaps does not exist. If the existing) race was not completed by the (participating) car in the race due to retirement but all lap times were available until retire- ment, the routine must not throw an error but return null. Note that in those error cases the function must not return a string but produce an SQL error. The total race time should be returned as an integer denoting millisec- onds. Note that this stored routine has three arguments and you must declare them in the order given above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago