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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"number" 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,
"constructorId" INT,
"position" INT,
"points" FLOAT,
PRIMARY KEY ("resultId")
);



INSERT INTO "drivers" VALUES ("101");
INSERT INTO "drivers" VALUES ("102");
INSERT INTO "drivers" VALUES ("103");
INSERT INTO "drivers" VALUES ("104");
INSERT INTO "drivers" VALUES ("105");
INSERT INTO "races" VALUES ("900");
INSERT INTO "races" VALUES ("901");
INSERT INTO "races" VALUES ("902");
INSERT INTO "races" VALUES ("903");
INSERT INTO "races" VALUES ("904");
INSERT INTO "qualifying" VALUES ("1", "900", "101", "44", "0:01:50.123");
INSERT INTO "qualifying" VALUES ("2", "901", "102", "33", "0:01:52.456");
INSERT INTO "qualifying" VALUES ("3", "902", "103", "77", "0:01:53.789");
INSERT INTO "qualifying" VALUES ("4", "903", "104", "22", "0:01:54.000");
INSERT INTO "qualifying" VALUES ("5", "903", "105", "11", "0:01:55.321");
INSERT INTO "results" VALUES ("1", "201", "1", "25.0");
INSERT INTO "results" VALUES ("2", "202", "2", "18.0");
INSERT INTO "results" VALUES ("3", "203", "3", "15.0");
INSERT INTO "results" VALUES ("4", "204", "4", "12.0");
INSERT INTO "results" VALUES ("5", "205", "5", "10.0");