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

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

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

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



INSERT INTO "circuits" VALUES ("1", "Circuit de Catalunya");
INSERT INTO "circuits" VALUES ("2", "Monaco Grand Prix");
INSERT INTO "circuits" VALUES ("3", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("4", "Spa-Francorchamps");
INSERT INTO "circuits" VALUES ("5", "Monza Circuit");
INSERT INTO "races" VALUES ("101", "2018", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("102", "2018", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("103", "2019", "British Grand Prix");
INSERT INTO "races" VALUES ("104", "2019", "Belgian Grand Prix");
INSERT INTO "races" VALUES ("105", "2020", "Italian Grand Prix");
INSERT INTO "races" VALUES ("106", "2020", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("107", "2021", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("108", "2021", "British Grand Prix");
INSERT INTO "races" VALUES ("109", "2022", "Belgian Grand Prix");
INSERT INTO "races" VALUES ("110", "2022", "Italian Grand Prix");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "91000");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "92000");
INSERT INTO "lapTimes" VALUES ("102", "1", "1", "100000");
INSERT INTO "lapTimes" VALUES ("102", "2", "1", "101000");
INSERT INTO "lapTimes" VALUES ("103", "3", "1", "85000");
INSERT INTO "lapTimes" VALUES ("103", "4", "1", "86000");
INSERT INTO "lapTimes" VALUES ("104", "3", "1", "87000");
INSERT INTO "lapTimes" VALUES ("105", "5", "1", "80000");
INSERT INTO "lapTimes" VALUES ("106", "1", "1", "93000");
INSERT INTO "lapTimes" VALUES ("106", "2", "1", "94000");
INSERT INTO "lapTimes" VALUES ("107", "1", "1", "102000");
INSERT INTO "lapTimes" VALUES ("108", "3", "1", "88000");
INSERT INTO "lapTimes" VALUES ("109", "3", "1", "89000");
INSERT INTO "lapTimes" VALUES ("110", "5", "1", "81000");
INSERT INTO "results" VALUES ("1", "101", "200.5");
INSERT INTO "results" VALUES ("2", "101", "199.8");
INSERT INTO "results" VALUES ("3", "102", "180.2");
INSERT INTO "results" VALUES ("4", "103", "210.1");
INSERT INTO "results" VALUES ("5", "104", "205.5");
INSERT INTO "results" VALUES ("6", "105", "220.0");
INSERT INTO "results" VALUES ("7", "106", "198.0");
INSERT INTO "results" VALUES ("8", "107", "178.5");
INSERT INTO "results" VALUES ("9", "108", "208.0");
INSERT INTO "results" VALUES ("10", "109", "203.0");
INSERT INTO "results" VALUES ("11", "110", "219.0");