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,
PRIMARY KEY ("circuitId")
);

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

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", "Melbourne");
INSERT INTO "circuits" VALUES ("2", "Sepang");
INSERT INTO "circuits" VALUES ("3", "Sakhir");
INSERT INTO "circuits" VALUES ("4", "Shanghai");
INSERT INTO "circuits" VALUES ("5", "Barcelona");
INSERT INTO "circuits" VALUES ("6", "Monte Carlo");
INSERT INTO "circuits" VALUES ("7", "Montreal");
INSERT INTO "circuits" VALUES ("8", "Spielberg");
INSERT INTO "circuits" VALUES ("9", "Silverstone");
INSERT INTO "circuits" VALUES ("10", "Hockenheim");
INSERT INTO "drivers" VALUES ("1", "Lewis");
INSERT INTO "drivers" VALUES ("2", "Max");
INSERT INTO "drivers" VALUES ("3", "Charles");
INSERT INTO "drivers" VALUES ("4", "Fernando");
INSERT INTO "drivers" VALUES ("5", "Sebastian");
INSERT INTO "races" VALUES ("1", "2023", "1", "Australian Grand Prix", "2023-03-05");
INSERT INTO "races" VALUES ("2", "2023", "3", "Bahrain Grand Prix", "2023-03-19");
INSERT INTO "races" VALUES ("3", "2023", "4", "Chinese Grand Prix", "2023-04-02");
INSERT INTO "races" VALUES ("4", "2022", "9", "British Grand Prix", "2022-07-03");
INSERT INTO "races" VALUES ("5", "2022", "6", "Monaco Grand Prix", "2022-05-29");
INSERT INTO "races" VALUES ("6", "2021", "7", "Canadian Grand Prix", "2021-06-13");
INSERT INTO "races" VALUES ("7", "2021", "8", "Austrian Grand Prix", "2021-07-04");
INSERT INTO "races" VALUES ("8", "2020", "5", "Spanish Grand Prix", "2020-08-16");
INSERT INTO "races" VALUES ("9", "2020", "10", "German Grand Prix", "2020-10-11");
INSERT INTO "races" VALUES ("10", "2019", "2", "Malaysian Grand Prix", "2019-03-31");
INSERT INTO "results" VALUES ("1", "1", "1", "58");
INSERT INTO "results" VALUES ("2", "1", "2", "58");
INSERT INTO "results" VALUES ("3", "2", "1", "57");
INSERT INTO "results" VALUES ("4", "2", "2", "57");
INSERT INTO "results" VALUES ("5", "3", "1", "56");
INSERT INTO "results" VALUES ("6", "4", "1", "52");
INSERT INTO "results" VALUES ("7", "5", "1", "78");
INSERT INTO "results" VALUES ("8", "6", "1", "70");
INSERT INTO "results" VALUES ("9", "7", "1", "71");
INSERT INTO "results" VALUES ("10", "8", "1", "66");
INSERT INTO "results" VALUES ("11", "9", "1", "67");
INSERT INTO "results" VALUES ("12", "10", "1", "56");
INSERT INTO "results" VALUES ("13", "1", "3", "58");
INSERT INTO "results" VALUES ("14", "5", "2", "78");
INSERT INTO "results" VALUES ("15", "7", "2", "71");
INSERT INTO "results" VALUES ("16", "9", "2", "67");