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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"q2" 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 ("22");
INSERT INTO "races" VALUES ("23");
INSERT INTO "races" VALUES ("24");
INSERT INTO "drivers" VALUES ("1", "hamilton", "Lewis", "Hamilton", "1985-01-07", "British");
INSERT INTO "drivers" VALUES ("2", "vettel", "Sebastian", "Vettel", "1987-07-03", "German");
INSERT INTO "drivers" VALUES ("3", "verstappen", "Max", "Verstappen", "1997-09-30", "Dutch");
INSERT INTO "drivers" VALUES ("4", "bottas", "Valtteri", "Bottas", "1989-08-28", "Finnish");
INSERT INTO "drivers" VALUES ("5", "leclerc", "Charles", "Leclerc", "1997-10-16", "Monegasque");
INSERT INTO "drivers" VALUES ("6", "norris", "Lando", "Norris", "1999-11-13", "British");
INSERT INTO "qualifying" VALUES ("101", "23", "1", "1", "1:12.345");
INSERT INTO "qualifying" VALUES ("102", "23", "2", "2", "1:12.678");
INSERT INTO "qualifying" VALUES ("103", "23", "3", "3", "NULL");
INSERT INTO "qualifying" VALUES ("104", "23", "4", "4", "1:13.001");
INSERT INTO "qualifying" VALUES ("105", "23", "5", "5", "NULL");
INSERT INTO "qualifying" VALUES ("106", "23", "6", "6", "1:13.456");
INSERT INTO "qualifying" VALUES ("107", "22", "1", "1", "1:11.999");
INSERT INTO "qualifying" VALUES ("108", "22", "2", "2", "NULL");
INSERT INTO "qualifying" VALUES ("109", "24", "3", "1", "1:12.222");