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

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

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

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



INSERT INTO "races" VALUES ("1", "1970");
INSERT INTO "races" VALUES ("2", "1971");
INSERT INTO "races" VALUES ("3", "1972");
INSERT INTO "races" VALUES ("4", "1973");
INSERT INTO "races" VALUES ("5", "1974");
INSERT INTO "races" VALUES ("6", "1975");
INSERT INTO "races" VALUES ("7", "1976");
INSERT INTO "results" VALUES ("1", "1", "1", "1:30:00.000", "5400000");
INSERT INTO "results" VALUES ("2", "1", "2", "1:30:05.000", "5405000");
INSERT INTO "results" VALUES ("3", "2", "1", "1:31:00.000", "5460000");
INSERT INTO "results" VALUES ("4", "2", "2", "1:31:10.000", "5470000");
INSERT INTO "results" VALUES ("5", "3", "1", "1:29:30.000", "5370000");
INSERT INTO "results" VALUES ("6", "3", "2", "1:29:45.000", "5385000");
INSERT INTO "results" VALUES ("7", "4", "1", "1:32:00.000", "5520000");
INSERT INTO "results" VALUES ("8", "4", "2", "1:32:01.000", "5521000");
INSERT INTO "results" VALUES ("9", "5", "1", "1:30:15.000", "5415000");
INSERT INTO "results" VALUES ("10", "5", "2", "1:30:20.000", "5420000");
INSERT INTO "results" VALUES ("11", "6", "1", "1:28:00.000", "5280000");
INSERT INTO "results" VALUES ("12", "7", "1", "1:27:00.000", "5220000");
INSERT INTO "results" VALUES ("13", "1", "3", "NULL", "NULL");
INSERT INTO "results" VALUES ("14", "2", "3", "NULL", "NULL");
INSERT INTO "results" VALUES ("15", "3", "3", "1:35:00.000", "5700000");
INSERT INTO "lapTimes" VALUES ("1", "101", "1", "90000");
INSERT INTO "lapTimes" VALUES ("1", "101", "2", "90000");
INSERT INTO "lapTimes" VALUES ("2", "102", "1", "91000");
INSERT INTO "lapTimes" VALUES ("2", "102", "2", "91000");
INSERT INTO "lapTimes" VALUES ("3", "103", "1", "89000");
INSERT INTO "lapTimes" VALUES ("3", "103", "2", "89000");
INSERT INTO "pitStops" VALUES ("1", "101", "1", "25000");
INSERT INTO "pitStops" VALUES ("2", "102", "1", "26000");
INSERT INTO "pitStops" VALUES ("3", "103", "1", "24000");
INSERT INTO "qualifying" VALUES ("1", "1");
INSERT INTO "qualifying" VALUES ("2", "2");
INSERT INTO "qualifying" VALUES ("3", "1");