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,
"location" 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", "Red Bull Ring", "Spielberg", "Austria");
INSERT INTO "circuits" VALUES ("2", "Silverstone Circuit", "Silverstone", "United Kingdom");
INSERT INTO "circuits" VALUES ("3", "Monza Circuit", "Monza", "Italy");
INSERT INTO "races" VALUES ("101", "1");
INSERT INTO "races" VALUES ("102", "1");
INSERT INTO "races" VALUES ("201", "2");
INSERT INTO "races" VALUES ("301", "3");
INSERT INTO "lapTimes" VALUES ("101", "11", "1", "1:05.432", "65432");
INSERT INTO "lapTimes" VALUES ("101", "11", "2", "1:04.987", "64987");
INSERT INTO "lapTimes" VALUES ("101", "12", "1", "1:05.432", "65432");
INSERT INTO "lapTimes" VALUES ("101", "12", "2", "1:05.000", "65000");
INSERT INTO "lapTimes" VALUES ("101", "13", "1", "1:04.987", "64987");
INSERT INTO "lapTimes" VALUES ("101", "13", "2", "1:04.987", "64987");
INSERT INTO "lapTimes" VALUES ("101", "14", "1", "1:06.000", "66000");
INSERT INTO "lapTimes" VALUES ("101", "14", "2", "1:05.500", "65500");
INSERT INTO "lapTimes" VALUES ("102", "11", "1", "1:05.200", "65200");
INSERT INTO "lapTimes" VALUES ("102", "11", "2", "1:04.800", "64800");
INSERT INTO "lapTimes" VALUES ("102", "12", "1", "1:05.100", "65100");
INSERT INTO "lapTimes" VALUES ("102", "12", "2", "1:04.900", "64900");
INSERT INTO "lapTimes" VALUES ("102", "13", "1", "1:04.800", "64800");
INSERT INTO "lapTimes" VALUES ("102", "13", "2", "1:04.850", "64850");
INSERT INTO "lapTimes" VALUES ("102", "14", "1", "1:05.300", "65300");
INSERT INTO "lapTimes" VALUES ("102", "14", "2", "1:05.000", "65000");
INSERT INTO "lapTimes" VALUES ("201", "21", "1", "1:25.000", "85000");
INSERT INTO "lapTimes" VALUES ("201", "21", "2", "1:24.500", "84500");
INSERT INTO "lapTimes" VALUES ("201", "22", "1", "1:24.800", "84800");
INSERT INTO "lapTimes" VALUES ("201", "22", "2", "1:24.700", "84700");
INSERT INTO "lapTimes" VALUES ("301", "31", "1", "1:20.000", "80000");
INSERT INTO "lapTimes" VALUES ("301", "31", "2", "1:19.500", "79500");
INSERT INTO "results" VALUES ("1", "1", "1:30:00.000", "5400000");
INSERT INTO "results" VALUES ("2", "2", "1:30:30.000", "5430000");
INSERT INTO "results" VALUES ("3", "3", "1:31:00.000", "5460000");