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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"constructorId" INT,
"position" INT,
"q1" 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 "drivers" VALUES ("1", "Bruno", "Senna", "Brazilian");
INSERT INTO "drivers" VALUES ("2", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("3", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso", "Spanish");
INSERT INTO "races" VALUES ("353");
INSERT INTO "races" VALUES ("354");
INSERT INTO "races" VALUES ("355");
INSERT INTO "qualifying" VALUES ("101", "353", "1", "10", "5", "1:20.345");
INSERT INTO "qualifying" VALUES ("102", "354", "1", "10", "7", "1:19.876");
INSERT INTO "qualifying" VALUES ("103", "354", "2", "11", "1", "1:18.234");
INSERT INTO "qualifying" VALUES ("104", "354", "3", "12", "2", "1:18.567");
INSERT INTO "qualifying" VALUES ("105", "355", "4", "13", "3", "1:21.000");
INSERT INTO "qualifying" VALUES ("106", "354", "4", "13", "10", "1:20.999");