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 "circuits" (
"circuitId" INT UNIQUE,
"name" TEXT,
"country" TEXT,
PRIMARY KEY ("circuitId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"position" INT,
"time" TEXT,
"milliseconds" INT,
PRIMARY KEY ("resultId")
);



INSERT INTO "circuits" VALUES ("1", "Monza Circuit", "Italy");
INSERT INTO "circuits" VALUES ("2", "Imola Circuit", "Italy");
INSERT INTO "circuits" VALUES ("3", "Mugello Circuit", "Italy");
INSERT INTO "circuits" VALUES ("4", "Silverstone Circuit", "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", "1");
INSERT INTO "races" VALUES ("105", "2");
INSERT INTO "races" VALUES ("106", "4");
INSERT INTO "lapTimes" VALUES ("101", "201", "1", "1:21.345", "81345");
INSERT INTO "lapTimes" VALUES ("101", "202", "1", "1:21.200", "81200");
INSERT INTO "lapTimes" VALUES ("101", "203", "1", "1:21.500", "81500");
INSERT INTO "lapTimes" VALUES ("101", "201", "2", "1:20.900", "80900");
INSERT INTO "lapTimes" VALUES ("101", "202", "2", "1:21.100", "81100");
INSERT INTO "lapTimes" VALUES ("101", "203", "2", "1:21.300", "81300");
INSERT INTO "lapTimes" VALUES ("104", "201", "1", "1:21.600", "81600");
INSERT INTO "lapTimes" VALUES ("104", "202", "1", "1:21.400", "81400");
INSERT INTO "lapTimes" VALUES ("104", "204", "1", "1:20.850", "80850");
INSERT INTO "lapTimes" VALUES ("104", "201", "2", "1:21.000", "81000");
INSERT INTO "lapTimes" VALUES ("104", "204", "2", "1:21.100", "81100");
INSERT INTO "lapTimes" VALUES ("102", "301", "1", "1:28.500", "88500");
INSERT INTO "lapTimes" VALUES ("102", "302", "1", "1:28.300", "88300");
INSERT INTO "lapTimes" VALUES ("102", "303", "1", "1:28.700", "88700");
INSERT INTO "lapTimes" VALUES ("102", "301", "2", "1:28.100", "88100");
INSERT INTO "lapTimes" VALUES ("102", "302", "2", "1:28.400", "88400");
INSERT INTO "lapTimes" VALUES ("105", "301", "1", "1:28.600", "88600");
INSERT INTO "lapTimes" VALUES ("105", "304", "1", "1:27.900", "87900");
INSERT INTO "lapTimes" VALUES ("105", "302", "1", "1:28.200", "88200");
INSERT INTO "lapTimes" VALUES ("105", "304", "2", "1:28.000", "88000");
INSERT INTO "lapTimes" VALUES ("103", "401", "1", "1:15.800", "75800");
INSERT INTO "lapTimes" VALUES ("103", "402", "1", "1:15.900", "75900");
INSERT INTO "lapTimes" VALUES ("103", "403", "1", "1:15.700", "75700");
INSERT INTO "lapTimes" VALUES ("103", "401", "2", "1:15.600", "75600");
INSERT INTO "lapTimes" VALUES ("103", "403", "2", "1:15.900", "75900");
INSERT INTO "lapTimes" VALUES ("106", "501", "1", "1:30.000", "90000");
INSERT INTO "lapTimes" VALUES ("106", "502", "1", "1:29.800", "89800");
INSERT INTO "lapTimes" VALUES ("106", "501", "2", "1:29.500", "89500");
INSERT INTO "results" VALUES ("1", "1", "1:30:00.000", "5400000");
INSERT INTO "results" VALUES ("2", "2", "1:30:05.000", "5405000");
INSERT INTO "results" VALUES ("3", "3", "1:30:10.000", "5410000");
INSERT INTO "results" VALUES ("4", "1", "1:29:50.000", "5390000");
INSERT INTO "results" VALUES ("5", "2", "1:29:55.000", "5395000");
INSERT INTO "results" VALUES ("6", "3", "1:30:00.000", "5400000");