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

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

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

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



INSERT INTO "races" VALUES ("1");
INSERT INTO "races" VALUES ("2");
INSERT INTO "races" VALUES ("743");
INSERT INTO "races" VALUES ("744");
INSERT INTO "races" VALUES ("745");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("3", "Bruce", "McLaren");
INSERT INTO "drivers" VALUES ("4", "Charles", "Leclerc");
INSERT INTO "drivers" VALUES ("5", "Fernando", "Alonso");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "1:20.000", "80000");
INSERT INTO "lapTimes" VALUES ("1", "1", "2", "1:21.000", "81000");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "1:20.500", "80500");
INSERT INTO "lapTimes" VALUES ("743", "3", "1", "1:30.000", "90000");
INSERT INTO "lapTimes" VALUES ("743", "3", "2", "1:31.000", "91000");
INSERT INTO "lapTimes" VALUES ("743", "3", "3", "1:32.000", "92000");
INSERT INTO "lapTimes" VALUES ("743", "1", "1", "1:28.000", "88000");
INSERT INTO "lapTimes" VALUES ("744", "4", "1", "1:25.000", "85000");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1:25:00.000", "5100000");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "1:25:05.000", "5105000");
INSERT INTO "results" VALUES ("3", "743", "3", "1", "1:35:00.000", "5700000");
INSERT INTO "results" VALUES ("4", "743", "1", "2", "1:35:10.000", "5710000");
INSERT INTO "results" VALUES ("5", "744", "4", "1", "1:28:00.000", "5280000");
INSERT INTO "results" VALUES ("6", "745", "5", "3", "1:30:00.000", "5400000");