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

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

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



INSERT INTO "drivers" VALUES ("1", "Hamilton", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("2", "vettel", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("3", "verstappen", "Max", "Verstappen", "Dutch");
INSERT INTO "drivers" VALUES ("4", "alonso", "Fernando", "Alonso", "Spanish");
INSERT INTO "drivers" VALUES ("5", "bottas", "Valtteri", "Bottas", "Finnish");
INSERT INTO "races" VALUES ("101", "2018", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2018", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("103", "2019", "British Grand Prix");
INSERT INTO "races" VALUES ("104", "2019", "Belgian Grand Prix");
INSERT INTO "races" VALUES ("105", "2020", "Italian Grand Prix");
INSERT INTO "races" VALUES ("106", "2020", "Abu Dhabi Grand Prix");
INSERT INTO "races" VALUES ("107", "2021", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("108", "2021", "Hungarian Grand Prix");
INSERT INTO "races" VALUES ("109", "2022", "British Grand Prix");
INSERT INTO "races" VALUES ("110", "2022", "Brazilian Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "1");
INSERT INTO "results" VALUES ("1002", "101", "2", "2");
INSERT INTO "results" VALUES ("1003", "101", "3", "3");
INSERT INTO "results" VALUES ("1004", "102", "1", "2");
INSERT INTO "results" VALUES ("1005", "102", "4", "1");
INSERT INTO "results" VALUES ("1006", "103", "1", "1");
INSERT INTO "results" VALUES ("1007", "103", "5", "3");
INSERT INTO "results" VALUES ("1008", "104", "2", "1");
INSERT INTO "results" VALUES ("1009", "104", "1", "4");
INSERT INTO "results" VALUES ("1010", "105", "3", "1");
INSERT INTO "results" VALUES ("1011", "105", "1", "3");
INSERT INTO "results" VALUES ("1012", "106", "1", "1");
INSERT INTO "results" VALUES ("1013", "106", "5", "2");
INSERT INTO "results" VALUES ("1014", "107", "1", "2");
INSERT INTO "results" VALUES ("1015", "107", "3", "1");
INSERT INTO "results" VALUES ("1016", "108", "4", "1");
INSERT INTO "results" VALUES ("1017", "108", "1", "3");
INSERT INTO "results" VALUES ("1018", "109", "3", "1");
INSERT INTO "results" VALUES ("1019", "109", "1", "2");
INSERT INTO "results" VALUES ("1020", "110", "1", "1");
INSERT INTO "results" VALUES ("1021", "110", "2", "3");