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", "Silverstone Circuit", "UK");
INSERT INTO "circuits" VALUES ("4", "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 "lapTimes" VALUES ("101", "201", "1", "1:21.345", "8145");
INSERT INTO "lapTimes" VALUES ("101", "202", "1", "1:20.999", "8099");
INSERT INTO "lapTimes" VALUES ("101", "203", "1", "1:21.500", "8150");
INSERT INTO "lapTimes" VALUES ("101", "201", "2", "1:20.800", "8080");
INSERT INTO "lapTimes" VALUES ("101", "202", "2", "1:20.700", "8070");
INSERT INTO "lapTimes" VALUES ("101", "203", "2", "1:21.000", "8100");
INSERT INTO "lapTimes" VALUES ("102", "204", "1", "1:28.500", "88500");
INSERT INTO "lapTimes" VALUES ("102", "205", "1", "1:28.300", "88300");
INSERT INTO "lapTimes" VALUES ("102", "206", "1", "1:28.700", "88700");
INSERT INTO "lapTimes" VALUES ("102", "204", "2", "1:28.100", "88100");
INSERT INTO "lapTimes" VALUES ("102", "205", "2", "1:28.000", "88000");
INSERT INTO "lapTimes" VALUES ("102", "206", "2", "1:28.400", "88400");
INSERT INTO "lapTimes" VALUES ("103", "207", "1", "1:30.000", "90000");
INSERT INTO "lapTimes" VALUES ("103", "208", "1", "1:29.800", "89800");
INSERT INTO "lapTimes" VALUES ("104", "209", "1", "1:45.000", "105000");
INSERT INTO "lapTimes" VALUES ("104", "210", "1", "1:44.500", "104500");
INSERT INTO "results" VALUES ("301", "1", "1:20.700", "8070");
INSERT INTO "results" VALUES ("302", "2", "1:28.000", "88000");
INSERT INTO "results" VALUES ("303", "3", "1:29.800", "89800");
INSERT INTO "results" VALUES ("304", "4", "1:44.500", "104500");