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 "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"position" INT,
"time" TEXT,
"milliseconds" INT,
PRIMARY KEY ("raceId", "driverId", "lap"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

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

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"name" TEXT,
PRIMARY KEY ("raceId")
);

CREATE TABLE "results" (
"resultId" INT,
"position" INT,
PRIMARY KEY ("resultId")
);



INSERT INTO "races" VALUES ("1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "French Grand Prix");
INSERT INTO "races" VALUES ("3", "Monaco Grand Prix");
INSERT INTO "drivers" VALUES ("101", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("102", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("103", "Max", "Verstappen", "Dutch");
INSERT INTO "drivers" VALUES ("104", "Charles", "Leclerc", "Monegasque");
INSERT INTO "drivers" VALUES ("105", "Daniel", "Ricciardo", "Australian");
INSERT INTO "lapTimes" VALUES ("2", "101", "3", "1", "1:15.500", "75500");
INSERT INTO "lapTimes" VALUES ("2", "102", "3", "2", "1:15.700", "75700");
INSERT INTO "lapTimes" VALUES ("2", "103", "3", "3", "1:15.900", "75900");
INSERT INTO "lapTimes" VALUES ("2", "104", "3", "4", "1:16.200", "76200");
INSERT INTO "lapTimes" VALUES ("2", "105", "3", "5", "1:15.800", "75800");
INSERT INTO "lapTimes" VALUES ("2", "101", "2", "1", "1:16.000", "76000");
INSERT INTO "lapTimes" VALUES ("2", "102", "2", "2", "1:16.100", "76100");
INSERT INTO "lapTimes" VALUES ("2", "103", "2", "3", "1:16.300", "76300");
INSERT INTO "lapTimes" VALUES ("2", "104", "2", "4", "1:16.400", "76400");
INSERT INTO "lapTimes" VALUES ("2", "105", "2", "5", "1:16.200", "76200");
INSERT INTO "lapTimes" VALUES ("1", "101", "3", "1", "1:14.500", "74500");
INSERT INTO "lapTimes" VALUES ("1", "102", "3", "2", "1:14.700", "74700");
INSERT INTO "lapTimes" VALUES ("1", "103", "3", "3", "1:14.900", "74900");
INSERT INTO "lapTimes" VALUES ("3", "101", "3", "1", "1:13.500", "73500");
INSERT INTO "lapTimes" VALUES ("3", "104", "3", "2", "1:13.700", "73700");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");
INSERT INTO "results" VALUES ("4", "4");
INSERT INTO "results" VALUES ("5", "5");