Question
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
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)
);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started