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,
"dob" DATE,
"nationality" TEXT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"date" DATE,
PRIMARY KEY ("raceId")
);

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



INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton", "1985-01-07", "British");
INSERT INTO "drivers" VALUES ("2", "Max", "Verstappen", "1997-09-30", "Dutch");
INSERT INTO "drivers" VALUES ("3", "Sebastian", "Vettel", "1987-07-03", "German");
INSERT INTO "drivers" VALUES ("4", "Charles", "Leclerc", "1997-10-16", "Monegasque");
INSERT INTO "drivers" VALUES ("5", "Lando", "Norris", "1999-11-13", "British");
INSERT INTO "drivers" VALUES ("6", "Fernando", "Alonso", "1981-07-29", "Spanish");
INSERT INTO "drivers" VALUES ("7", "George", "Russell", "1998-02-15", "British");
INSERT INTO "drivers" VALUES ("8", "Kimi", "Raikkonen", "1979-10-17", "Finnish");
INSERT INTO "races" VALUES ("870", "2023-07-02");
INSERT INTO "races" VALUES ("871", "2023-07-09");
INSERT INTO "races" VALUES ("872", "2023-07-16");
INSERT INTO "races" VALUES ("873", "2023-07-23");
INSERT INTO "results" VALUES ("1", "872", "1", "2", "1:30:15.123");
INSERT INTO "results" VALUES ("2", "872", "2", "1", "1:29:50.456");
INSERT INTO "results" VALUES ("3", "872", "3", "5", "1:31:10.789");
INSERT INTO "results" VALUES ("4", "872", "4", "3", "1:30:45.321");
INSERT INTO "results" VALUES ("5", "872", "5", "4", "1:30:50.654");
INSERT INTO "results" VALUES ("6", "872", "6", "6", "1:31:20.987");
INSERT INTO "results" VALUES ("7", "872", "7", "7", "1:31:45.000");
INSERT INTO "results" VALUES ("8", "872", "8", "8", "NULL");
INSERT INTO "results" VALUES ("9", "871", "1", "1", "1:28:00.000");
INSERT INTO "results" VALUES ("10", "871", "2", "2", "1:28:30.000");