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"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId")
);

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

CREATE TABLE "circuits" (
"circuitId" INT UNIQUE,
"name" TEXT,
"country" TEXT,
PRIMARY KEY ("circuitId")
);

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

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

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"circuitId" INT,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

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



INSERT INTO "circuits" VALUES ("1", "Monza", "Italy");
INSERT INTO "circuits" VALUES ("2", "Imola", "Italy");
INSERT INTO "circuits" VALUES ("3", "Mugello", "Italy");
INSERT INTO "circuits" VALUES ("4", "Silverstone", "UK");
INSERT INTO "circuits" VALUES ("5", "Spa-Francorchamps", "Belgium");
INSERT INTO "races" VALUES ("101", "1");
INSERT INTO "races" VALUES ("102", "2");
INSERT INTO "races" VALUES ("103", "3");
INSERT INTO "races" VALUES ("104", "4");
INSERT INTO "races" VALUES ("105", "1");
INSERT INTO "races" VALUES ("106", "2");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "1:25.000", "85000");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "1:24.500", "84500");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "1:26.000", "86000");
INSERT INTO "lapTimes" VALUES ("101", "2", "2", "1:25.200", "85200");
INSERT INTO "lapTimes" VALUES ("102", "1", "1", "1:20.000", "80000");
INSERT INTO "lapTimes" VALUES ("102", "1", "2", "1:19.800", "79800");
INSERT INTO "lapTimes" VALUES ("102", "2", "1", "1:21.000", "81000");
INSERT INTO "lapTimes" VALUES ("103", "1", "1", "1:18.000", "78000");
INSERT INTO "lapTimes" VALUES ("103", "1", "2", "1:17.500", "77500");
INSERT INTO "lapTimes" VALUES ("104", "1", "1", "1:30.000", "90000");
INSERT INTO "lapTimes" VALUES ("105", "1", "1", "1:24.000", "84000");
INSERT INTO "lapTimes" VALUES ("105", "1", "2", "1:23.900", "83900");
INSERT INTO "lapTimes" VALUES ("106", "2", "1", "1:19.500", "79500");
INSERT INTO "results" VALUES ("1", "101", "5000000", "1:24.500");
INSERT INTO "results" VALUES ("2", "102", "4800000", "1:19.800");
INSERT INTO "results" VALUES ("3", "103", "4700000", "1:17.500");
INSERT INTO "results" VALUES ("4", "104", "5500000", "1:30.000");
INSERT INTO "results" VALUES ("5", "105", "4900000", "1:23.900");
INSERT INTO "results" VALUES ("6", "106", "4750000", "1:19.500");
INSERT INTO "drivers" VALUES ("1", "Lewis");
INSERT INTO "drivers" VALUES ("2", "Max");
INSERT INTO "drivers" VALUES ("3", "Charles");
INSERT INTO "pitStops" VALUES ("101", "1", "1", "25000");
INSERT INTO "pitStops" VALUES ("102", "1", "1", "22000");
INSERT INTO "qualifying" VALUES ("1", "1:23.000");
INSERT INTO "qualifying" VALUES ("2", "1:18.000");