PRAGMA foreign_keys = ON;

PRAGMA writable_schema = 1;
DELETE FROM sqlite_master WHERE type IN ("table", "index", "trigger");
PRAGMA writable_schema = 0;
VACUUM;

CREATE TABLE "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"milliseconds" INT,
PRIMARY KEY ("raceId", "driverId", "lap"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

CREATE TABLE "constructors" (
"constructorId" INT,
"name" TEXT,
PRIMARY KEY ("constructorId")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"surname" TEXT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"name" TEXT,
PRIMARY KEY ("raceId")
);

CREATE TABLE "results" (
"resultId" INT,
"milliseconds" INT,
PRIMARY KEY ("resultId")
);



INSERT INTO "constructors" VALUES ("1", "Mercedes");
INSERT INTO "constructors" VALUES ("2", "Red Bull");
INSERT INTO "constructors" VALUES ("3", "Ferrari");
INSERT INTO "constructors" VALUES ("4", "McLaren");
INSERT INTO "constructors" VALUES ("5", "Aston Martin");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("3", "Charles", "Leclerc");
INSERT INTO "drivers" VALUES ("4", "Lando", "Norris");
INSERT INTO "drivers" VALUES ("5", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("6", "Sergio", "Perez");
INSERT INTO "drivers" VALUES ("7", "Carlos", "Sainz");
INSERT INTO "drivers" VALUES ("8", "George", "Russell");
INSERT INTO "races" VALUES ("1", "2023", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("2", "2023", "Saudi Arabian Grand Prix");
INSERT INTO "races" VALUES ("3", "2023", "Australian Grand Prix");
INSERT INTO "races" VALUES ("4", "2022", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("5", "2022", "British Grand Prix");
INSERT INTO "races" VALUES ("6", "2021", "Italian Grand Prix");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "95000");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "94500");
INSERT INTO "lapTimes" VALUES ("1", "3", "1", "96000");
INSERT INTO "lapTimes" VALUES ("2", "1", "1", "93000");
INSERT INTO "lapTimes" VALUES ("2", "2", "1", "92500");
INSERT INTO "lapTimes" VALUES ("2", "3", "1", "93500");
INSERT INTO "lapTimes" VALUES ("3", "4", "1", "98000");
INSERT INTO "lapTimes" VALUES ("3", "5", "1", "97500");
INSERT INTO "lapTimes" VALUES ("4", "2", "1", "80000");
INSERT INTO "lapTimes" VALUES ("4", "3", "1", "80500");
INSERT INTO "lapTimes" VALUES ("5", "1", "1", "85000");
INSERT INTO "lapTimes" VALUES ("5", "4", "1", "84500");
INSERT INTO "lapTimes" VALUES ("6", "6", "1", "88000");
INSERT INTO "lapTimes" VALUES ("6", "7", "1", "87500");
INSERT INTO "lapTimes" VALUES ("6", "8", "1", "88200");
INSERT INTO "results" VALUES ("1", "95000");
INSERT INTO "results" VALUES ("2", "94500");
INSERT INTO "results" VALUES ("3", "96000");
INSERT INTO "results" VALUES ("4", "93000");
INSERT INTO "results" VALUES ("5", "92500");
INSERT INTO "results" VALUES ("6", "93500");
INSERT INTO "results" VALUES ("7", "98000");
INSERT INTO "results" VALUES ("8", "97500");
INSERT INTO "results" VALUES ("9", "80000");
INSERT INTO "results" VALUES ("10", "80500");
INSERT INTO "results" VALUES ("11", "85000");
INSERT INTO "results" VALUES ("12", "84500");
INSERT INTO "results" VALUES ("13", "88000");
INSERT INTO "results" VALUES ("14", "87500");
INSERT INTO "results" VALUES ("15", "88200");