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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"milliseconds" INT,
"fastestLapTime" TEXT,
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", "Max", "Verstappen", "Dutch");
INSERT INTO "drivers" VALUES ("3", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("4", "Charles", "Leclerc", "Monegasque");
INSERT INTO "drivers" VALUES ("5", "Lando", "Norris", "British");
INSERT INTO "races" VALUES ("101", "Monaco Grand Prix", "2023-05-28");
INSERT INTO "races" VALUES ("102", "British Grand Prix", "2023-07-09");
INSERT INTO "races" VALUES ("103", "Belgian Grand Prix", "2023-08-27");
INSERT INTO "races" VALUES ("104", "Italian Grand Prix", "2023-09-03");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "5400000", "1:12.345");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "5405000", "1:12.678");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "5410000", "1:13.000");
INSERT INTO "results" VALUES ("1004", "102", "4", "1", "5300000", "1:11.234");
INSERT INTO "results" VALUES ("1005", "102", "5", "2", "5305000", "1:11.567");
INSERT INTO "results" VALUES ("1006", "102", "1", "3", "5310000", "1:11.890");
INSERT INTO "results" VALUES ("1007", "103", "2", "1", "5200000", "1:10.123");
INSERT INTO "results" VALUES ("1008", "103", "3", "2", "5220000", "1:10.456");
INSERT INTO "results" VALUES ("1009", "103", "4", "3", "5230000", "1:10.789");
INSERT INTO "results" VALUES ("1010", "104", "5", "1", "5500000", "1:13.456");
INSERT INTO "results" VALUES ("1011", "104", "1", "2", "5510000", "1:13.789");
INSERT INTO "results" VALUES ("1012", "104", "2", "3", "5520000", "1:14.000");