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 "circuits" (
"circuitId" INT UNIQUE,
"location" TEXT,
"country" TEXT,
PRIMARY KEY ("circuitId")
);

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

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



INSERT INTO "circuits" VALUES ("1", "Monza", "Italy");
INSERT INTO "circuits" VALUES ("2", "Silverstone", "United Kingdom");
INSERT INTO "circuits" VALUES ("3", "Spa-Francorchamps", "Belgium");
INSERT INTO "circuits" VALUES ("4", "Suzuka", "Japan");
INSERT INTO "circuits" VALUES ("5", "Interlagos", "Brazil");
INSERT INTO "races" VALUES ("101", "2018", "1", "Italian Grand Prix", "2018-09-02");
INSERT INTO "races" VALUES ("102", "2019", "2", "British Grand Prix", "2019-07-14");
INSERT INTO "races" VALUES ("103", "2020", "3", "Belgian Grand Prix", "2020-08-30");
INSERT INTO "races" VALUES ("104", "2021", "4", "Japanese Grand Prix", "2021-10-10");
INSERT INTO "races" VALUES ("105", "2022", "5", "Brazilian Grand Prix", "2022-11-13");
INSERT INTO "races" VALUES ("106", "2023", "3", "Belgian Grand Prix", "2023-08-27");
INSERT INTO "results" VALUES ("1001", "101", "1", "53");
INSERT INTO "results" VALUES ("1002", "101", "2", "53");
INSERT INTO "results" VALUES ("1003", "102", "1", "52");
INSERT INTO "results" VALUES ("1004", "102", "2", "52");
INSERT INTO "results" VALUES ("1005", "103", "1", "44");
INSERT INTO "results" VALUES ("1006", "103", "2", "44");
INSERT INTO "results" VALUES ("1007", "104", "1", "53");
INSERT INTO "results" VALUES ("1008", "104", "2", "53");
INSERT INTO "results" VALUES ("1009", "105", "1", "71");
INSERT INTO "results" VALUES ("1010", "105", "2", "71");
INSERT INTO "results" VALUES ("1011", "106", "1", "44");
INSERT INTO "results" VALUES ("1012", "106", "2", "44");