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 "qualifying" (
"qualifyId" INT,
"q3" TEXT,
PRIMARY KEY ("qualifyId")
);

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

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



INSERT INTO "races" VALUES ("1", "2020");
INSERT INTO "races" VALUES ("2", "2019");
INSERT INTO "races" VALUES ("3", "2018");
INSERT INTO "races" VALUES ("4", "2017");
INSERT INTO "races" VALUES ("5", "2016");
INSERT INTO "races" VALUES ("6", "2015");
INSERT INTO "races" VALUES ("7", "2014");
INSERT INTO "races" VALUES ("8", "2013");
INSERT INTO "races" VALUES ("9", "2012");
INSERT INTO "races" VALUES ("10", "2011");
INSERT INTO "lapTimes" VALUES ("1", "101", "1", "0:01:25.000");
INSERT INTO "lapTimes" VALUES ("1", "101", "2", "0:01:24.500");
INSERT INTO "lapTimes" VALUES ("1", "102", "1", "0:01:26.000");
INSERT INTO "lapTimes" VALUES ("2", "103", "1", "0:01:23.000");
INSERT INTO "lapTimes" VALUES ("2", "103", "2", "0:01:22.800");
INSERT INTO "lapTimes" VALUES ("3", "104", "1", "0:01:27.000");
INSERT INTO "lapTimes" VALUES ("4", "105", "1", "0:01:21.000");
INSERT INTO "lapTimes" VALUES ("4", "105", "2", "0:01:20.500");
INSERT INTO "lapTimes" VALUES ("5", "106", "1", "0:01:28.000");
INSERT INTO "lapTimes" VALUES ("6", "107", "1", "0:01:29.000");
INSERT INTO "lapTimes" VALUES ("7", "108", "1", "0:01:30.000");
INSERT INTO "lapTimes" VALUES ("8", "109", "1", "0:01:31.000");
INSERT INTO "lapTimes" VALUES ("9", "110", "1", "0:01:32.000");
INSERT INTO "lapTimes" VALUES ("10", "111", "1", "0:01:33.000");
INSERT INTO "pitStops" VALUES ("1", "101", "1", "25.000");
INSERT INTO "pitStops" VALUES ("1", "102", "1", "26.000");
INSERT INTO "pitStops" VALUES ("2", "103", "1", "24.000");
INSERT INTO "pitStops" VALUES ("4", "105", "1", "23.000");
INSERT INTO "pitStops" VALUES ("7", "108", "1", "27.000");
INSERT INTO "qualifying" VALUES ("1", "1:24.000");
INSERT INTO "qualifying" VALUES ("2", "1:23.500");
INSERT INTO "qualifying" VALUES ("3", "1:25.000");
INSERT INTO "qualifying" VALUES ("4", "1:20.000");
INSERT INTO "qualifying" VALUES ("5", "1:27.000");
INSERT INTO "qualifying" VALUES ("6", "1:28.000");
INSERT INTO "qualifying" VALUES ("7", "1:29.000");
INSERT INTO "qualifying" VALUES ("8", "1:30.000");
INSERT INTO "qualifying" VALUES ("9", "1:31.000");
INSERT INTO "qualifying" VALUES ("10", "1:32.000");
INSERT INTO "results" VALUES ("1", "1", "0:01:24.500");
INSERT INTO "results" VALUES ("2", "2", "0:01:22.800");
INSERT INTO "results" VALUES ("3", "3", "0:01:27.000");
INSERT INTO "results" VALUES ("4", "4", "0:01:20.500");
INSERT INTO "results" VALUES ("5", "5", "0:01:28.000");
INSERT INTO "results" VALUES ("6", "6", "0:01:29.000");
INSERT INTO "results" VALUES ("7", "7", "0:01:30.000");
INSERT INTO "results" VALUES ("8", "8", "0:01:31.000");
INSERT INTO "results" VALUES ("9", "9", "0:01:32.000");
INSERT INTO "results" VALUES ("10", "10", "0:01:33.000");
INSERT INTO "results" VALUES ("11", "1", "NULL");
INSERT INTO "results" VALUES ("12", "2", "NULL");
INSERT INTO "results" VALUES ("13", "3", "NULL");
INSERT INTO "results" VALUES ("14", "4", "NULL");
INSERT INTO "results" VALUES ("15", "5", "NULL");