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,
"surname" 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")
);

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



INSERT INTO "drivers" VALUES ("1", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Verstappen");
INSERT INTO "drivers" VALUES ("3", "Bottas");
INSERT INTO "drivers" VALUES ("4", "Leclerc");
INSERT INTO "drivers" VALUES ("5", "Norris");
INSERT INTO "races" VALUES ("18");
INSERT INTO "races" VALUES ("19");
INSERT INTO "races" VALUES ("20");
INSERT INTO "qualifying" VALUES ("101", "19", "1", "2", "1:28.345");
INSERT INTO "qualifying" VALUES ("102", "19", "2", "1", "1:27.890");
INSERT INTO "qualifying" VALUES ("103", "19", "3", "3", "1:28.500");
INSERT INTO "qualifying" VALUES ("104", "19", "4", "4", "1:29.000");
INSERT INTO "qualifying" VALUES ("105", "19", "5", "5", "1:30.100");
INSERT INTO "qualifying" VALUES ("106", "18", "1", "1", "1:27.500");
INSERT INTO "qualifying" VALUES ("107", "18", "2", "2", "1:27.700");
INSERT INTO "qualifying" VALUES ("108", "20", "3", "1", "1:28.000");
INSERT INTO "qualifying" VALUES ("109", "20", "4", "2", "1:28.200");
INSERT INTO "results" VALUES ("201", "1", "25.0");
INSERT INTO "results" VALUES ("202", "2", "18.0");
INSERT INTO "results" VALUES ("203", "3", "15.0");
INSERT INTO "results" VALUES ("204", "4", "12.0");
INSERT INTO "results" VALUES ("205", "5", "10.0");