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")
);

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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"q1" TEXT,
PRIMARY KEY ("qualifyId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

CREATE TABLE "results" (
"resultId" INT,
"position" INT,
"points" FLOAT,
PRIMARY KEY ("resultId")
);



INSERT INTO "drivers" VALUES ("1", "hamilton");
INSERT INTO "drivers" VALUES ("2", "verstappen");
INSERT INTO "drivers" VALUES ("3", "bottas");
INSERT INTO "drivers" VALUES ("4", "norris");
INSERT INTO "drivers" VALUES ("5", "ricciardo");
INSERT INTO "drivers" VALUES ("6", "perez");
INSERT INTO "drivers" VALUES ("7", "leclerc");
INSERT INTO "drivers" VALUES ("8", "sainz");
INSERT INTO "drivers" VALUES ("9", "alonso");
INSERT INTO "drivers" VALUES ("10", "ocon");
INSERT INTO "qualifying" VALUES ("101", "20", "1", "1", "01:10.500");
INSERT INTO "qualifying" VALUES ("102", "20", "2", "2", "01:10.700");
INSERT INTO "qualifying" VALUES ("103", "20", "3", "3", "01:10.900");
INSERT INTO "qualifying" VALUES ("104", "20", "4", "4", "01:11.200");
INSERT INTO "qualifying" VALUES ("105", "20", "5", "5", "01:11.500");
INSERT INTO "qualifying" VALUES ("106", "20", "6", "6", "01:12.000");
INSERT INTO "qualifying" VALUES ("107", "20", "7", "7", "01:12.300");
INSERT INTO "qualifying" VALUES ("108", "20", "8", "8", "01:12.600");
INSERT INTO "qualifying" VALUES ("109", "20", "9", "9", "01:12.900");
INSERT INTO "qualifying" VALUES ("110", "20", "10", "10", "01:13.200");
INSERT INTO "results" VALUES ("201", "1", "25.0");
INSERT INTO "results" VALUES ("202", "2", "18.0");
INSERT INTO "results" VALUES ("203", "3", "15.0");
INSERT INTO "results" VALUES ("204", "4", "12.0");
INSERT INTO "results" VALUES ("205", "5", "10.0");
INSERT INTO "results" VALUES ("206", "6", "8.0");
INSERT INTO "results" VALUES ("207", "7", "6.0");
INSERT INTO "results" VALUES ("208", "8", "4.0");
INSERT INTO "results" VALUES ("209", "9", "2.0");
INSERT INTO "results" VALUES ("210", "10", "1.0");
INSERT INTO "lapTimes" VALUES ("20", "1", "1", "70000");
INSERT INTO "lapTimes" VALUES ("20", "1", "2", "69500");
INSERT INTO "lapTimes" VALUES ("20", "2", "1", "70200");
INSERT INTO "lapTimes" VALUES ("20", "2", "2", "69800");
INSERT INTO "lapTimes" VALUES ("20", "3", "1", "70500");
INSERT INTO "lapTimes" VALUES ("20", "3", "2", "70000");
INSERT INTO "lapTimes" VALUES ("20", "4", "1", "71000");
INSERT INTO "lapTimes" VALUES ("20", "4", "2", "70500");
INSERT INTO "lapTimes" VALUES ("20", "5", "1", "71500");
INSERT INTO "lapTimes" VALUES ("20", "5", "2", "71000");
INSERT INTO "lapTimes" VALUES ("20", "6", "1", "72000");
INSERT INTO "lapTimes" VALUES ("20", "6", "2", "71500");
INSERT INTO "lapTimes" VALUES ("20", "7", "1", "72500");
INSERT INTO "lapTimes" VALUES ("20", "7", "2", "72000");
INSERT INTO "lapTimes" VALUES ("20", "8", "1", "73000");
INSERT INTO "lapTimes" VALUES ("20", "8", "2", "72500");
INSERT INTO "lapTimes" VALUES ("20", "9", "1", "73500");
INSERT INTO "lapTimes" VALUES ("20", "9", "2", "73000");
INSERT INTO "lapTimes" VALUES ("20", "10", "1", "74000");
INSERT INTO "lapTimes" VALUES ("20", "10", "2", "73500");