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,
"forename" TEXT,
"surname" TEXT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"q1" TEXT,
PRIMARY KEY ("qualifyId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

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



INSERT INTO "races" VALUES ("1");
INSERT INTO "races" VALUES ("2");
INSERT INTO "races" VALUES ("354");
INSERT INTO "races" VALUES ("355");
INSERT INTO "races" VALUES ("356");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Bruno", "Senna");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Jenson", "Button");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "90500");
INSERT INTO "lapTimes" VALUES ("354", "3", "1", "91000");
INSERT INTO "lapTimes" VALUES ("354", "4", "1", "91200");
INSERT INTO "lapTimes" VALUES ("355", "1", "1", "89000");
INSERT INTO "qualifying" VALUES ("1", "1", "1", "1", "1:25.000");
INSERT INTO "qualifying" VALUES ("2", "1", "2", "2", "1:25.100");
INSERT INTO "qualifying" VALUES ("3", "354", "3", "5", "1:26.500");
INSERT INTO "qualifying" VALUES ("4", "354", "4", "6", "1:26.700");
INSERT INTO "qualifying" VALUES ("5", "354", "1", "1", "1:24.800");
INSERT INTO "qualifying" VALUES ("6", "355", "3", "8", "1:27.000");
INSERT INTO "qualifying" VALUES ("7", "356", "3", "3", "1:26.000");
INSERT INTO "qualifying" VALUES ("8", "354", "5", "7", "1:26.800");