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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"q1" TEXT,
PRIMARY KEY ("qualifyId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"points" FLOAT,
"milliseconds" INT,
"fastestLap" 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");
INSERT INTO "drivers" VALUES ("2", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("3", "Charles", "Leclerc");
INSERT INTO "drivers" VALUES ("4", "George", "Russell");
INSERT INTO "drivers" VALUES ("5", "Sergio", "Perez");
INSERT INTO "races" VALUES ("1001", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("1002", "Saudi Arabian Grand Prix");
INSERT INTO "races" VALUES ("1003", "Australian Grand Prix");
INSERT INTO "races" VALUES ("1004", "Monaco Grand Prix");
INSERT INTO "lapTimes" VALUES ("1001", "1", "1", "1:35.000", "95000");
INSERT INTO "lapTimes" VALUES ("1001", "1", "2", "1:33.500", "93500");
INSERT INTO "lapTimes" VALUES ("1001", "1", "3", "1:34.000", "94000");
INSERT INTO "lapTimes" VALUES ("1001", "2", "1", "1:34.800", "94800");
INSERT INTO "lapTimes" VALUES ("1001", "2", "2", "1:33.200", "93200");
INSERT INTO "lapTimes" VALUES ("1002", "1", "1", "1:32.000", "92000");
INSERT INTO "lapTimes" VALUES ("1002", "1", "2", "1:31.800", "91800");
INSERT INTO "lapTimes" VALUES ("1002", "3", "1", "1:32.500", "92500");
INSERT INTO "lapTimes" VALUES ("1003", "1", "1", "1:28.000", "88000");
INSERT INTO "lapTimes" VALUES ("1003", "1", "2", "1:27.500", "87500");
INSERT INTO "lapTimes" VALUES ("1003", "4", "1", "1:27.800", "87800");
INSERT INTO "lapTimes" VALUES ("1004", "1", "1", "1:15.000", "75000");
INSERT INTO "lapTimes" VALUES ("1004", "1", "2", "1:14.900", "74900");
INSERT INTO "lapTimes" VALUES ("1004", "5", "1", "1:14.850", "74850");
INSERT INTO "results" VALUES ("1", "1001", "1", "3", "15.0", "93500", "2", "1:33.500");
INSERT INTO "results" VALUES ("2", "1001", "2", "1", "25.0", "93200", "2", "1:33.200");
INSERT INTO "results" VALUES ("3", "1002", "1", "2", "18.0", "91800", "2", "1:31.800");
INSERT INTO "results" VALUES ("4", "1002", "3", "1", "25.0", "92500", "1", "1:32.500");
INSERT INTO "results" VALUES ("5", "1003", "1", "4", "12.0", "87500", "2", "1:27.500");
INSERT INTO "results" VALUES ("6", "1003", "4", "3", "15.0", "87800", "1", "1:27.800");
INSERT INTO "results" VALUES ("7", "1004", "1", "1", "25.0", "74900", "2", "1:14.900");
INSERT INTO "results" VALUES ("8", "1004", "5", "2", "18.0", "74850", "1", "1:14.850");
INSERT INTO "qualifying" VALUES ("1", "1:30.000");
INSERT INTO "qualifying" VALUES ("2", "1:29.500");