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

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

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

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



INSERT INTO "lapTimes" VALUES ("1", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "88000");
INSERT INTO "lapTimes" VALUES ("1", "3", "1", "92000");
INSERT INTO "lapTimes" VALUES ("2", "1", "1", "85000");
INSERT INTO "lapTimes" VALUES ("2", "4", "1", "87000");
INSERT INTO "lapTimes" VALUES ("3", "5", "1", "91000");
INSERT INTO "lapTimes" VALUES ("3", "6", "1", "89000");
INSERT INTO "lapTimes" VALUES ("4", "7", "1", "86000");
INSERT INTO "lapTimes" VALUES ("4", "8", "1", "93000");
INSERT INTO "lapTimes" VALUES ("5", "9", "1", "84000");
INSERT INTO "drivers" VALUES ("1", "MSC", "1969-01-03", "German");
INSERT INTO "drivers" VALUES ("2", "ALO", "1981-07-29", "Spanish");
INSERT INTO "drivers" VALUES ("3", "VET", "1987-07-03", "German");
INSERT INTO "drivers" VALUES ("4", "RAI", "1979-10-17", "Finnish");
INSERT INTO "drivers" VALUES ("5", "HAM", "1985-01-07", "British");
INSERT INTO "drivers" VALUES ("6", "BOT", "1989-08-28", "Finnish");
INSERT INTO "drivers" VALUES ("7", "VER", "1997-09-30", "Dutch");
INSERT INTO "drivers" VALUES ("8", "PER", "1990-01-26", "Mexican");
INSERT INTO "drivers" VALUES ("9", "RIC", "1989-07-01", "Australian");
INSERT INTO "drivers" VALUES ("10", "WEB", "1976-08-27", "Australian");
INSERT INTO "drivers" VALUES ("11", "COU", "1971-03-27", "British");
INSERT INTO "drivers" VALUES ("12", "BAR", "1972-05-23", "Brazilian");
INSERT INTO "drivers" VALUES ("13", "TRU", "1974-07-13", "Italian");
INSERT INTO "drivers" VALUES ("14", "HEI", "1971-10-03", "German");
INSERT INTO "drivers" VALUES ("15", "FIS", "1973-01-14", "Italian");
INSERT INTO "races" VALUES ("1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("3", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("4", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("5", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("6", "Monaco Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1", "NULL");
INSERT INTO "results" VALUES ("2", "1", "2", "1:28.000");
INSERT INTO "results" VALUES ("3", "1", "3", "NULL");
INSERT INTO "results" VALUES ("4", "2", "1", "1:25.000");
INSERT INTO "results" VALUES ("5", "2", "4", "NULL");
INSERT INTO "results" VALUES ("6", "3", "5", "NULL");
INSERT INTO "results" VALUES ("7", "3", "6", "1:29.000");
INSERT INTO "results" VALUES ("8", "4", "7", "1:26.000");
INSERT INTO "results" VALUES ("9", "4", "8", "NULL");
INSERT INTO "results" VALUES ("10", "5", "9", "1:24.000");
INSERT INTO "results" VALUES ("11", "5", "10", "NULL");
INSERT INTO "results" VALUES ("12", "1", "11", "1:27.500");
INSERT INTO "results" VALUES ("13", "2", "12", "NULL");
INSERT INTO "results" VALUES ("14", "3", "13", "1:30.100");
INSERT INTO "results" VALUES ("15", "4", "14", "1:25.900");
INSERT INTO "results" VALUES ("16", "5", "15", "NULL");
INSERT INTO "results" VALUES ("17", "1", "14", "1:27.000");
INSERT INTO "results" VALUES ("18", "2", "11", "NULL");