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

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

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



INSERT INTO "drivers" VALUES ("101", "Lewis", "Hamilton", "1985-01-07", "United Kingdom");
INSERT INTO "drivers" VALUES ("102", "Sebastian", "Vettel", "1987-07-03", "Germany");
INSERT INTO "drivers" VALUES ("103", "Max", "Verstappen", "1997-09-30", "Netherlands");
INSERT INTO "drivers" VALUES ("104", "Charles", "Leclerc", "1997-10-16", "Monaco");
INSERT INTO "drivers" VALUES ("105", "Daniel", "Ricciardo", "1989-07-01", "Australia");
INSERT INTO "races" VALUES ("346", "2023-07-09");
INSERT INTO "races" VALUES ("347", "2023-07-16");
INSERT INTO "races" VALUES ("348", "2023-07-23");
INSERT INTO "qualifying" VALUES ("201", "346", "101", "1", "0:01:14");
INSERT INTO "qualifying" VALUES ("202", "347", "101", "1", "0:01:16");
INSERT INTO "qualifying" VALUES ("203", "347", "102", "2", "0:01:15");
INSERT INTO "qualifying" VALUES ("204", "347", "103", "3", "0:01:17");
INSERT INTO "qualifying" VALUES ("205", "348", "104", "4", "0:01:18");
INSERT INTO "qualifying" VALUES ("206", "347", "105", "5", "0:01:20");