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 "circuits" (
"circuitId" INT UNIQUE,
"name" TEXT,
PRIMARY KEY ("circuitId")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"forename" 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,
"year" INT,
"circuitId" INT,
"name" TEXT,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);



INSERT INTO "circuits" VALUES ("1", "Marina Bay Street Circuit");
INSERT INTO "circuits" VALUES ("2", "Monaco Grand Prix");
INSERT INTO "circuits" VALUES ("3", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("4", "Suzuka Circuit");
INSERT INTO "circuits" VALUES ("5", "Circuit de Spa-Francorchamps");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Felipe", "Massa");
INSERT INTO "drivers" VALUES ("3", "Kimi", "Raikkonen");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("6", "Robert", "Kubica");
INSERT INTO "drivers" VALUES ("7", "Nick", "Heidfeld");
INSERT INTO "races" VALUES ("1", "2008", "1", "Singapore Grand Prix");
INSERT INTO "races" VALUES ("2", "2008", "2", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("3", "2009", "1", "Singapore Grand Prix");
INSERT INTO "races" VALUES ("4", "2008", "3", "British Grand Prix");
INSERT INTO "races" VALUES ("5", "2007", "1", "Singapore Grand Prix");
INSERT INTO "qualifying" VALUES ("1", "1", "1", "1", "1:44.500");
INSERT INTO "qualifying" VALUES ("2", "1", "2", "2", "1:44.800");
INSERT INTO "qualifying" VALUES ("3", "1", "3", "3", "1:45.100");
INSERT INTO "qualifying" VALUES ("4", "1", "4", "4", "1:45.200");
INSERT INTO "qualifying" VALUES ("5", "1", "5", "5", "1:45.300");
INSERT INTO "qualifying" VALUES ("6", "2", "1", "1", "1:15.000");
INSERT INTO "qualifying" VALUES ("7", "2", "2", "2", "1:15.100");
INSERT INTO "qualifying" VALUES ("8", "3", "1", "1", "1:46.000");
INSERT INTO "qualifying" VALUES ("9", "1", "6", "6", "1:45.400");
INSERT INTO "qualifying" VALUES ("10", "1", "7", "7", "1:45.500");