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,
"time" TEXT,
PRIMARY KEY ("raceId", "driverId", "lap")
);

CREATE TABLE "pitStops" (
"raceId" INT,
"driverId" INT,
"stop" INT,
"duration" TEXT,
PRIMARY KEY ("raceId", "driverId", "stop")
);

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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"q3" TEXT,
PRIMARY KEY ("qualifyId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"fastestLapTime" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);



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", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Sergio", "Perez");
INSERT INTO "races" VALUES ("1001");
INSERT INTO "races" VALUES ("1002");
INSERT INTO "races" VALUES ("1003");
INSERT INTO "races" VALUES ("1004");
INSERT INTO "races" VALUES ("1005");
INSERT INTO "results" VALUES ("1", "1001", "1", "1:20.500");
INSERT INTO "results" VALUES ("2", "1001", "2", "1:21.100");
INSERT INTO "results" VALUES ("3", "1002", "1", "1:19.800");
INSERT INTO "results" VALUES ("4", "1002", "3", "1:20.000");
INSERT INTO "results" VALUES ("5", "1003", "1", "1:20.100");
INSERT INTO "results" VALUES ("6", "1003", "4", "1:20.300");
INSERT INTO "results" VALUES ("7", "1004", "2", "1:19.500");
INSERT INTO "results" VALUES ("8", "1004", "1", "1:20.050");
INSERT INTO "results" VALUES ("9", "1005", "1", "1:19.750");
INSERT INTO "results" VALUES ("10", "1005", "5", "1:20.200");
INSERT INTO "lapTimes" VALUES ("1001", "1", "1", "1:22.000");
INSERT INTO "lapTimes" VALUES ("1001", "1", "2", "1:21.500");
INSERT INTO "lapTimes" VALUES ("1001", "1", "3", "1:20.500");
INSERT INTO "lapTimes" VALUES ("1002", "1", "1", "1:21.000");
INSERT INTO "lapTimes" VALUES ("1002", "1", "2", "1:19.800");
INSERT INTO "lapTimes" VALUES ("1003", "1", "1", "1:20.800");
INSERT INTO "lapTimes" VALUES ("1003", "1", "2", "1:20.100");
INSERT INTO "lapTimes" VALUES ("1004", "1", "1", "1:20.700");
INSERT INTO "lapTimes" VALUES ("1004", "1", "2", "1:20.050");
INSERT INTO "lapTimes" VALUES ("1005", "1", "1", "1:20.000");
INSERT INTO "lapTimes" VALUES ("1005", "1", "2", "1:19.750");
INSERT INTO "pitStops" VALUES ("1001", "1", "1", "2.500");
INSERT INTO "pitStops" VALUES ("1002", "1", "1", "2.300");
INSERT INTO "pitStops" VALUES ("1003", "1", "1", "2.600");
INSERT INTO "qualifying" VALUES ("1", "1:20.000");
INSERT INTO "qualifying" VALUES ("2", "1:19.500");
INSERT INTO "qualifying" VALUES ("3", "1:20.200");