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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"q3" 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")
);

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



INSERT INTO "drivers" VALUES ("1", "HAM", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "VER", "Verstappen");
INSERT INTO "drivers" VALUES ("3", "LEC", "Leclerc");
INSERT INTO "drivers" VALUES ("4", "SAI", "Sainz");
INSERT INTO "drivers" VALUES ("5", "RUS", "Russell");
INSERT INTO "races" VALUES ("44");
INSERT INTO "races" VALUES ("45");
INSERT INTO "races" VALUES ("46");
INSERT INTO "qualifying" VALUES ("101", "45", "1", "1", "0:01:33");
INSERT INTO "qualifying" VALUES ("102", "45", "2", "2", "0:01:31");
INSERT INTO "qualifying" VALUES ("103", "45", "3", "3", "0:01:34");
INSERT INTO "qualifying" VALUES ("104", "45", "4", "4", "0:01:35");
INSERT INTO "qualifying" VALUES ("105", "45", "5", "5", "0:01:36");
INSERT INTO "qualifying" VALUES ("106", "44", "1", "1", "0:01:32");
INSERT INTO "qualifying" VALUES ("107", "44", "2", "2", "0:01:33");
INSERT INTO "qualifying" VALUES ("108", "44", "3", "3", "0:01:34");
INSERT INTO "qualifying" VALUES ("109", "46", "1", "1", "0:01:30");
INSERT INTO "qualifying" VALUES ("110", "46", "2", "2", "0:01:31");
INSERT INTO "qualifying" VALUES ("111", "46", "3", "3", "0:01:32");
INSERT INTO "results" VALUES ("201", "1");
INSERT INTO "results" VALUES ("202", "2");
INSERT INTO "results" VALUES ("203", "3");
INSERT INTO "results" VALUES ("204", "4");
INSERT INTO "results" VALUES ("205", "5");