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"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId")
);

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

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

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



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 "lapTimes" VALUES ("1", "101", "1", "95000");
INSERT INTO "lapTimes" VALUES ("1", "102", "1", "96000");
INSERT INTO "lapTimes" VALUES ("1", "101", "2", "94000");
INSERT INTO "lapTimes" VALUES ("2", "103", "1", "93000");
INSERT INTO "lapTimes" VALUES ("2", "104", "1", "92000");
INSERT INTO "lapTimes" VALUES ("3", "105", "1", "91000");
INSERT INTO "lapTimes" VALUES ("3", "106", "1", "90000");
INSERT INTO "lapTimes" VALUES ("4", "107", "1", "98000");
INSERT INTO "lapTimes" VALUES ("4", "108", "1", "97000");
INSERT INTO "lapTimes" VALUES ("5", "109", "1", "89000");
INSERT INTO "lapTimes" VALUES ("5", "110", "1", "90500");
INSERT INTO "lapTimes" VALUES ("6", "111", "1", "91500");
INSERT INTO "lapTimes" VALUES ("6", "112", "1", "92500");
INSERT INTO "qualifying" VALUES ("1", "1:25.000");
INSERT INTO "qualifying" VALUES ("2", "1:24.500");
INSERT INTO "qualifying" VALUES ("3", "1:23.000");
INSERT INTO "results" VALUES ("1", "1", "5400000");
INSERT INTO "results" VALUES ("2", "2", "5401000");
INSERT INTO "results" VALUES ("3", "1", "5500000");