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

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

CREATE TABLE "drivers" (
"driverId" INT,
"surname" TEXT,
PRIMARY KEY ("driverId")
);

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

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



INSERT INTO "circuits" VALUES ("1", "Italy");
INSERT INTO "circuits" VALUES ("2", "France");
INSERT INTO "circuits" VALUES ("3", "Italy");
INSERT INTO "circuits" VALUES ("4", "Germany");
INSERT INTO "drivers" VALUES ("101", "Hamilton");
INSERT INTO "drivers" VALUES ("102", "Vettel");
INSERT INTO "drivers" VALUES ("103", "Alonso");
INSERT INTO "drivers" VALUES ("104", "Leclerc");
INSERT INTO "races" VALUES ("201", "2020", "1");
INSERT INTO "races" VALUES ("202", "2021", "2");
INSERT INTO "races" VALUES ("203", "2020", "3");
INSERT INTO "races" VALUES ("204", "2021", "4");
INSERT INTO "lapTimes" VALUES ("201", "101", "1", "90000");
INSERT INTO "lapTimes" VALUES ("201", "102", "1", "91000");
INSERT INTO "lapTimes" VALUES ("201", "103", "1", "92000");
INSERT INTO "lapTimes" VALUES ("201", "104", "1", "89000");
INSERT INTO "lapTimes" VALUES ("202", "101", "1", "88000");
INSERT INTO "lapTimes" VALUES ("202", "102", "1", "87000");
INSERT INTO "lapTimes" VALUES ("202", "103", "1", "86000");
INSERT INTO "lapTimes" VALUES ("202", "104", "1", "85000");
INSERT INTO "lapTimes" VALUES ("203", "101", "1", "88000");
INSERT INTO "lapTimes" VALUES ("203", "102", "1", "87000");
INSERT INTO "lapTimes" VALUES ("203", "103", "1", "86000");
INSERT INTO "lapTimes" VALUES ("203", "104", "1", "85000");
INSERT INTO "lapTimes" VALUES ("204", "101", "1", "95000");
INSERT INTO "lapTimes" VALUES ("204", "102", "1", "94000");
INSERT INTO "lapTimes" VALUES ("204", "103", "1", "93000");
INSERT INTO "lapTimes" VALUES ("204", "104", "1", "92000");
INSERT INTO "results" VALUES ("301", "1");
INSERT INTO "results" VALUES ("302", "2");
INSERT INTO "results" VALUES ("303", "3");
INSERT INTO "results" VALUES ("304", "4");