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", "Bahrain International Circuit");
INSERT INTO "circuits" VALUES ("2", "Melbourne Grand Prix Circuit");
INSERT INTO "circuits" VALUES ("3", "Shanghai International Circuit");
INSERT INTO "circuits" VALUES ("4", "Baku City Circuit");
INSERT INTO "circuits" VALUES ("5", "Circuit de Barcelona-Catalunya");
INSERT INTO "races" VALUES ("1", "2020", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("2", "2020", "Australian Grand Prix");
INSERT INTO "races" VALUES ("3", "2021", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("4", "2021", "Azerbaijan Grand Prix");
INSERT INTO "races" VALUES ("5", "2022", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("6", "2022", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("7", "2023", "British Grand Prix");
INSERT INTO "lapTimes" VALUES ("1", "101", "1", "90000");
INSERT INTO "lapTimes" VALUES ("1", "101", "2", "91000");
INSERT INTO "lapTimes" VALUES ("2", "102", "1", "88000");
INSERT INTO "lapTimes" VALUES ("2", "102", "2", "89000");
INSERT INTO "lapTimes" VALUES ("3", "103", "1", "95000");
INSERT INTO "lapTimes" VALUES ("3", "103", "2", "96000");
INSERT INTO "lapTimes" VALUES ("4", "104", "1", "93000");
INSERT INTO "lapTimes" VALUES ("4", "104", "2", "94000");
INSERT INTO "lapTimes" VALUES ("5", "105", "1", "92000");
INSERT INTO "lapTimes" VALUES ("5", "105", "2", "93000");
INSERT INTO "lapTimes" VALUES ("6", "106", "1", "100000");
INSERT INTO "lapTimes" VALUES ("6", "106", "2", "101000");
INSERT INTO "lapTimes" VALUES ("7", "107", "1", "87000");
INSERT INTO "lapTimes" VALUES ("7", "107", "2", "88000");
INSERT INTO "results" VALUES ("1", "1", "200.5");
INSERT INTO "results" VALUES ("2", "2", "205.1");
INSERT INTO "results" VALUES ("3", "3", "190.2");
INSERT INTO "results" VALUES ("4", "4", "195.8");
INSERT INTO "results" VALUES ("5", "5", "198.0");
INSERT INTO "results" VALUES ("6", "6", "180.0");
INSERT INTO "results" VALUES ("7", "7", "210.0");