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

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

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



INSERT INTO "races" VALUES ("1");
INSERT INTO "races" VALUES ("2");
INSERT INTO "drivers" VALUES ("101", "Michael", "Schumacher", "1969-01-03", "German");
INSERT INTO "drivers" VALUES ("102", "Sebastian", "Vettel", "1987-07-03", "German");
INSERT INTO "drivers" VALUES ("103", "Nico", "Rosberg", "1985-06-27", "German");
INSERT INTO "drivers" VALUES ("104", "Timo", "Glock", "1982-03-18", "German");
INSERT INTO "drivers" VALUES ("105", "Ralf", "Schumacher", "1975-06-30", "German");
INSERT INTO "drivers" VALUES ("106", "Felipe", "Massa", "1981-04-25", "Brazilian");
INSERT INTO "drivers" VALUES ("107", "Lewis", "Hamilton", "1985-01-07", "British");
INSERT INTO "drivers" VALUES ("108", "Nico", "Hulkenberg", "1987-08-19", "German");
INSERT INTO "drivers" VALUES ("109", "Sebastian", "Buemi", "1988-10-31", "Swiss");
INSERT INTO "lapTimes" VALUES ("1", "102", "1", "1:20.500", "80500");
INSERT INTO "lapTimes" VALUES ("1", "102", "2", "1:19.800", "79800");
INSERT INTO "lapTimes" VALUES ("1", "103", "1", "1:20.000", "80000");
INSERT INTO "lapTimes" VALUES ("1", "103", "2", "1:19.700", "79700");
INSERT INTO "lapTimes" VALUES ("1", "104", "1", "1:21.000", "81000");
INSERT INTO "lapTimes" VALUES ("1", "104", "2", "1:20.200", "80200");
INSERT INTO "lapTimes" VALUES ("2", "108", "1", "1:19.600", "79600");
INSERT INTO "lapTimes" VALUES ("2", "108", "2", "1:19.400", "79400");
INSERT INTO "lapTimes" VALUES ("2", "102", "3", "1:19.300", "79300");
INSERT INTO "lapTimes" VALUES ("2", "103", "3", "1:19.500", "79500");
INSERT INTO "lapTimes" VALUES ("1", "101", "1", "1:18.000", "78000");
INSERT INTO "lapTimes" VALUES ("1", "105", "1", "1:22.000", "82000");
INSERT INTO "lapTimes" VALUES ("1", "106", "1", "1:19.000", "79000");
INSERT INTO "lapTimes" VALUES ("1", "107", "1", "1:18.500", "78500");
INSERT INTO "lapTimes" VALUES ("1", "109", "1", "1:20.000", "80000");
INSERT INTO "results" VALUES ("1", "1", "1:19.300", "79300");
INSERT INTO "results" VALUES ("2", "2", "1:19.400", "79400");
INSERT INTO "results" VALUES ("3", "3", "1:19.500", "79500");
INSERT INTO "results" VALUES ("4", "4", "1:19.600", "79600");
INSERT INTO "results" VALUES ("5", "5", "1:19.700", "79700");