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 "races" (
"raceId" INT UNIQUE,
"year" INT,
"name" TEXT,
"date" DATE,
PRIMARY KEY ("raceId")
);

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



INSERT INTO "races" VALUES ("1", "2020", "Australian Grand Prix", "2020-03-15");
INSERT INTO "races" VALUES ("2", "2020", "Bahrain Grand Prix", "2020-03-22");
INSERT INTO "races" VALUES ("3", "2021", "Monaco Grand Prix", "2021-05-23");
INSERT INTO "races" VALUES ("4", "2021", "British Grand Prix", "2021-07-18");
INSERT INTO "races" VALUES ("5", "2022", "Italian Grand Prix", "2022-09-11");
INSERT INTO "results" VALUES ("101", "1", "11", "1", "5400000");
INSERT INTO "results" VALUES ("102", "1", "12", "2", "5420000");
INSERT INTO "results" VALUES ("103", "1", "13", "3", "5450000");
INSERT INTO "results" VALUES ("104", "2", "21", "1", "5300000");
INSERT INTO "results" VALUES ("105", "2", "22", "2", "5330000");
INSERT INTO "results" VALUES ("106", "2", "23", "3", "null");
INSERT INTO "results" VALUES ("107", "3", "31", "1", "5500000");
INSERT INTO "results" VALUES ("108", "3", "32", "2", "5520000");
INSERT INTO "results" VALUES ("109", "4", "41", "1", "5250000");
INSERT INTO "results" VALUES ("110", "4", "42", "2", "5270000");
INSERT INTO "results" VALUES ("111", "5", "51", "1", "5250000");
INSERT INTO "results" VALUES ("112", "5", "52", "2", "5280000");
INSERT INTO "results" VALUES ("113", "5", "53", "3", "5300000");