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 "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"surname" TEXT,
"nationality" TEXT,
PRIMARY KEY ("driverId")
);

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

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



INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("3", "Max", "Verstappen", "Dutch");
INSERT INTO "drivers" VALUES ("4", "Charles", "Leclerc", "Monegasque");
INSERT INTO "drivers" VALUES ("5", "Valtteri", "Bottas", "Finnish");
INSERT INTO "races" VALUES ("101", "2018");
INSERT INTO "races" VALUES ("102", "2019");
INSERT INTO "races" VALUES ("103", "2020");
INSERT INTO "races" VALUES ("104", "2021");
INSERT INTO "races" VALUES ("105", "2022");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "01:25.345");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "01:26.123");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "01:26.789");
INSERT INTO "results" VALUES ("1004", "102", "1", "2", "01:24.876");
INSERT INTO "results" VALUES ("1005", "102", "4", "1", "01:24.500");
INSERT INTO "results" VALUES ("1006", "103", "1", "1", "01:23.999");
INSERT INTO "results" VALUES ("1007", "103", "5", "3", "01:25.111");
INSERT INTO "results" VALUES ("1008", "104", "1", "3", "01:24.250");
INSERT INTO "results" VALUES ("1009", "104", "3", "1", "01:23.800");
INSERT INTO "results" VALUES ("1010", "105", "1", "1", "01:22.500");
INSERT INTO "results" VALUES ("1011", "105", "2", "2", "01:23.000");
INSERT INTO "results" VALUES ("1012", "105", "4", "4", "01:24.000");