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

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,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

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



INSERT INTO "circuits" VALUES ("1", "Albert Park Grand Prix Circuit");
INSERT INTO "circuits" VALUES ("2", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("3", "Marina Bay Street Circuit");
INSERT INTO "circuits" VALUES ("4", "Monza Circuit");
INSERT INTO "constructors" VALUES ("1", "Ferrari");
INSERT INTO "constructors" VALUES ("2", "McLaren");
INSERT INTO "constructors" VALUES ("3", "Red Bull Racing");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("4", "Kimi", "Raikkonen");
INSERT INTO "drivers" VALUES ("5", "Jenson", "Button");
INSERT INTO "drivers" VALUES ("6", "Mark", "Webber");
INSERT INTO "races" VALUES ("1", "2008", "1");
INSERT INTO "races" VALUES ("2", "2008", "2");
INSERT INTO "races" VALUES ("3", "2008", "3");
INSERT INTO "races" VALUES ("4", "2008", "4");
INSERT INTO "races" VALUES ("5", "2009", "3");
INSERT INTO "qualifying" VALUES ("1", "1", "1", "1", "01:23.456");
INSERT INTO "qualifying" VALUES ("2", "1", "2", "2", "01:24.000");
INSERT INTO "qualifying" VALUES ("3", "2", "3", "1", "01:22.500");
INSERT INTO "qualifying" VALUES ("4", "2", "4", "2", "01:23.000");
INSERT INTO "qualifying" VALUES ("5", "3", "5", "3", "01:25.000");
INSERT INTO "qualifying" VALUES ("6", "3", "6", "2", "01:24.500");
INSERT INTO "qualifying" VALUES ("7", "3", "1", "1", "01:23.200");
INSERT INTO "qualifying" VALUES ("8", "3", "2", "4", "NULL");
INSERT INTO "qualifying" VALUES ("9", "3", "3", "5", "01:26.000");
INSERT INTO "qualifying" VALUES ("10", "4", "4", "1", "01:21.000");
INSERT INTO "qualifying" VALUES ("11", "4", "5", "2", "01:21.500");
INSERT INTO "qualifying" VALUES ("12", "5", "6", "1", "01:22.000");
INSERT INTO "qualifying" VALUES ("13", "5", "1", "2", "01:22.500");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");
INSERT INTO "results" VALUES ("4", "4");
INSERT INTO "results" VALUES ("5", "5");