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 "driverStandings" (
"driverStandingsId" INT,
"points" FLOAT,
PRIMARY KEY ("driverStandingsId")
);

CREATE TABLE "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"milliseconds" INT,
PRIMARY KEY ("raceId", "driverId", "lap")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"code" TEXT,
"dob" DATE,
PRIMARY KEY ("driverId")
);

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



INSERT INTO "driverStandings" VALUES ("1", "150.5");
INSERT INTO "driverStandings" VALUES ("2", "120.0");
INSERT INTO "driverStandings" VALUES ("3", "98.0");
INSERT INTO "driverStandings" VALUES ("4", "75.0");
INSERT INTO "driverStandings" VALUES ("5", "60.0");
INSERT INTO "drivers" VALUES ("1", "HAM", "1971-05-13");
INSERT INTO "drivers" VALUES ("2", "VET", "1971-08-05");
INSERT INTO "drivers" VALUES ("3", "ALO", "1981-07-29");
INSERT INTO "drivers" VALUES ("4", "RAI", "1971-10-13");
INSERT INTO "drivers" VALUES ("5", "BOT", "1990-01-06");
INSERT INTO "results" VALUES ("1", "101", "1", "1", "1:20.345");
INSERT INTO "results" VALUES ("2", "101", "2", "2", "1:20.345");
INSERT INTO "results" VALUES ("3", "101", "3", "3", "1:21.000");
INSERT INTO "results" VALUES ("4", "101", "4", "4", "1:22.500");
INSERT INTO "results" VALUES ("5", "101", "5", "5", "NULL");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "80345");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "80400");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "80345");
INSERT INTO "lapTimes" VALUES ("101", "2", "2", "80500");
INSERT INTO "lapTimes" VALUES ("101", "3", "1", "81000");
INSERT INTO "lapTimes" VALUES ("101", "4", "1", "82500");
INSERT INTO "lapTimes" VALUES ("101", "5", "1", "83000");