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

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"nationality" TEXT,
PRIMARY KEY ("driverId")
);

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

CREATE TABLE "races" (
"raceId" INT,
"name" TEXT,
PRIMARY KEY ("raceId")
);



INSERT INTO "constructors" VALUES ("1", "British");
INSERT INTO "constructors" VALUES ("2", "German");
INSERT INTO "constructors" VALUES ("3", "Italian");
INSERT INTO "constructors" VALUES ("4", "French");
INSERT INTO "constructors" VALUES ("5", "Austrian");
INSERT INTO "drivers" VALUES ("101", "British");
INSERT INTO "drivers" VALUES ("102", "German");
INSERT INTO "drivers" VALUES ("103", "Spanish");
INSERT INTO "drivers" VALUES ("104", "French");
INSERT INTO "drivers" VALUES ("105", "Finnish");
INSERT INTO "drivers" VALUES ("106", "Dutch");
INSERT INTO "drivers" VALUES ("107", "Mexican");
INSERT INTO "races" VALUES ("350", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("351", "British Grand Prix");
INSERT INTO "races" VALUES ("352", "Italian Grand Prix");
INSERT INTO "races" VALUES ("353", "Japanese Grand Prix");
INSERT INTO "races" VALUES ("354", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("355", "Abu Dhabi Grand Prix");
INSERT INTO "races" VALUES ("356", "Australian Grand Prix");
INSERT INTO "qualifying" VALUES ("1", "350", "101", "0:01:25.123", "0:01:24.567");
INSERT INTO "qualifying" VALUES ("2", "350", "102", "0:01:25.345", "0:01:24.789");
INSERT INTO "qualifying" VALUES ("3", "351", "101", "0:01:20.000", "0:01:19.500");
INSERT INTO "qualifying" VALUES ("4", "351", "103", "0:01:21.000", "0:01:20.500");
INSERT INTO "qualifying" VALUES ("5", "355", "104", "0:01:41.000", "0:01:40.000");
INSERT INTO "qualifying" VALUES ("6", "355", "105", "0:01:40.500", "0:01:40.200");
INSERT INTO "qualifying" VALUES ("7", "355", "106", "0:01:40.000", "0:01:39.800");
INSERT INTO "qualifying" VALUES ("8", "352", "104", "0:01:28.000", "0:01:27.500");
INSERT INTO "qualifying" VALUES ("9", "353", "104", "0:01:35.000", "0:01:34.000");
INSERT INTO "qualifying" VALUES ("10", "355", "107", "0:01:40.100", "0:01:40.000");
INSERT INTO "qualifying" VALUES ("11", "356", "107", "0:01:22.000", "0:01:21.500");