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

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

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

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



INSERT INTO "circuits" VALUES ("1", "Italy");
INSERT INTO "circuits" VALUES ("2", "Monaco");
INSERT INTO "circuits" VALUES ("3", "Italy");
INSERT INTO "circuits" VALUES ("4", "Brazil");
INSERT INTO "circuits" VALUES ("5", "Italy");
INSERT INTO "races" VALUES ("101", "2023", "1", "Italian Grand Prix");
INSERT INTO "races" VALUES ("102", "2023", "2", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("103", "2022", "3", "Emilia Romagna Grand Prix");
INSERT INTO "races" VALUES ("104", "2022", "4", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("105", "2021", "5", "Tuscan Grand Prix");
INSERT INTO "races" VALUES ("106", "2021", "1", "Italian Grand Prix");
INSERT INTO "races" VALUES ("107", "2020", "3", "Emilia Romagna Grand Prix");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "80000");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "79500");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "81000");
INSERT INTO "lapTimes" VALUES ("103", "3", "1", "82000");
INSERT INTO "lapTimes" VALUES ("103", "3", "2", "81500");
INSERT INTO "lapTimes" VALUES ("105", "4", "1", "83000");
INSERT INTO "lapTimes" VALUES ("105", "4", "2", "82500");
INSERT INTO "lapTimes" VALUES ("106", "5", "1", "79000");
INSERT INTO "lapTimes" VALUES ("107", "6", "1", "80500");
INSERT INTO "lapTimes" VALUES ("102", "7", "1", "90000");
INSERT INTO "lapTimes" VALUES ("104", "8", "1", "85000");
INSERT INTO "results" VALUES ("1", "1:20:00.000");
INSERT INTO "results" VALUES ("2", "1:21:00.000");
INSERT INTO "results" VALUES ("3", "1:22:00.000");
INSERT INTO "results" VALUES ("4", "1:23:00.000");
INSERT INTO "results" VALUES ("5", "1:24:00.000");