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

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

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

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



INSERT INTO "circuits" VALUES ("1", "Circuit de Monaco");
INSERT INTO "circuits" VALUES ("2", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("3", "Autodromo Nazionale Monza");
INSERT INTO "circuits" VALUES ("4", "Circuit de Spa-Francorchamps");
INSERT INTO "circuits" VALUES ("5", "Suzuka International Racing Course");
INSERT INTO "races" VALUES ("101", "Monaco Grand Prix", "2023-05-28");
INSERT INTO "races" VALUES ("102", "British Grand Prix", "2023-07-09");
INSERT INTO "races" VALUES ("103", "Italian Grand Prix", "2023-09-03");
INSERT INTO "races" VALUES ("104", "Belgian Grand Prix", "2023-07-30");
INSERT INTO "races" VALUES ("105", "Japanese Grand Prix", "2023-09-24");
INSERT INTO "races" VALUES ("106", "Spanish Grand Prix", "2023-06-04");
INSERT INTO "races" VALUES ("107", "Hungarian Grand Prix", "2023-07-23");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "01:15.000");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "01:14.500");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "01:16.000");
INSERT INTO "lapTimes" VALUES ("102", "3", "1", "01:28.000");
INSERT INTO "lapTimes" VALUES ("102", "3", "2", "01:27.500");
INSERT INTO "lapTimes" VALUES ("103", "4", "1", "01:20.000");
INSERT INTO "lapTimes" VALUES ("103", "4", "2", "01:19.800");
INSERT INTO "lapTimes" VALUES ("104", "5", "1", "01:45.000");
INSERT INTO "lapTimes" VALUES ("104", "5", "2", "01:44.900");
INSERT INTO "lapTimes" VALUES ("105", "6", "1", "01:32.000");
INSERT INTO "lapTimes" VALUES ("105", "6", "2", "01:31.500");
INSERT INTO "lapTimes" VALUES ("106", "7", "1", "01:18.000");
INSERT INTO "lapTimes" VALUES ("107", "8", "1", "01:22.000");
INSERT INTO "results" VALUES ("1", "101", "01:14.500", "200.500");
INSERT INTO "results" VALUES ("2", "102", "01:27.500", "220.100");
INSERT INTO "results" VALUES ("3", "103", "01:19.800", "240.300");
INSERT INTO "results" VALUES ("4", "104", "01:44.900", "210.000");
INSERT INTO "results" VALUES ("5", "105", "01:31.500", "235.700");
INSERT INTO "results" VALUES ("6", "106", "01:17.800", "205.200");
INSERT INTO "results" VALUES ("7", "107", "01:21.900", "215.800");
INSERT INTO "results" VALUES ("8", "101", "01:14.800", "199.000");
INSERT INTO "results" VALUES ("9", "103", "01:20.100", "239.500");
INSERT INTO "results" VALUES ("10", "102", "01:28.000", "219.000");