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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"number" 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 "drivers" VALUES ("1", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("3", "Lucas", "di Grassi", "Brazilian");
INSERT INTO "drivers" VALUES ("4", "Max", "Verstappen", "Dutch");
INSERT INTO "drivers" VALUES ("5", "Fernando", "Alonso", "Spanish");
INSERT INTO "races" VALUES ("344");
INSERT INTO "races" VALUES ("345");
INSERT INTO "races" VALUES ("346");
INSERT INTO "qualifying" VALUES ("101", "344", "1", "44", "1:20.345");
INSERT INTO "qualifying" VALUES ("102", "344", "3", "17", "1:21.123");
INSERT INTO "qualifying" VALUES ("103", "345", "3", "17", "1:19.876");
INSERT INTO "qualifying" VALUES ("104", "345", "2", "5", "1:20.001");
INSERT INTO "qualifying" VALUES ("105", "345", "4", "33", "1:19.500");
INSERT INTO "qualifying" VALUES ("106", "346", "5", "14", "1:22.000");
INSERT INTO "qualifying" VALUES ("107", "346", "3", "17", "1:21.500");