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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"rank" INT,
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", "Lando", "Norris", "British");
INSERT INTO "races" VALUES ("101", "2023", "1", "11", "Bahrain Grand Prix", "2023-03-05");
INSERT INTO "races" VALUES ("102", "2023", "2", "12", "Saudi Arabian Grand Prix", "2023-03-19");
INSERT INTO "races" VALUES ("103", "2023", "3", "13", "Australian Grand Prix", "2023-04-02");
INSERT INTO "races" VALUES ("104", "2023", "4", "14", "Azerbaijan Grand Prix", "2023-04-30");
INSERT INTO "races" VALUES ("105", "2023", "5", "15", "Miami Grand Prix", "2023-05-07");
INSERT INTO "results" VALUES ("1001", "101", "1", "2", "2");
INSERT INTO "results" VALUES ("1002", "101", "2", "1", "1");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "3");
INSERT INTO "results" VALUES ("1004", "102", "1", "1", "1");
INSERT INTO "results" VALUES ("1005", "102", "3", "2", "2");
INSERT INTO "results" VALUES ("1006", "102", "4", "3", "3");
INSERT INTO "results" VALUES ("1007", "103", "1", "3", "3");
INSERT INTO "results" VALUES ("1008", "103", "5", "1", "1");
INSERT INTO "results" VALUES ("1009", "103", "2", "2", "2");
INSERT INTO "results" VALUES ("1010", "104", "1", "1", "1");
INSERT INTO "results" VALUES ("1011", "104", "4", "2", "2");
INSERT INTO "results" VALUES ("1012", "104", "3", "3", "3");
INSERT INTO "results" VALUES ("1013", "105", "5", "2", "2");
INSERT INTO "results" VALUES ("1014", "105", "1", "4", "4");
INSERT INTO "results" VALUES ("1015", "105", "2", "1", "1");