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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"q3" TEXT,
PRIMARY KEY ("qualifyId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"time" TEXT,
"fastestLapSpeed" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId")
);



INSERT INTO "circuits" VALUES ("1", "Circuit de Barcelona-Catalunya");
INSERT INTO "circuits" VALUES ("2", "Monaco Grand Prix");
INSERT INTO "circuits" VALUES ("3", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("4", "Autodromo Nazionale Monza");
INSERT INTO "circuits" VALUES ("5", "Suzuka Circuit");
INSERT INTO "qualifying" VALUES ("1", "1:20.000");
INSERT INTO "qualifying" VALUES ("2", "1:15.500");
INSERT INTO "qualifying" VALUES ("3", "1:25.100");
INSERT INTO "qualifying" VALUES ("4", "1:18.700");
INSERT INTO "qualifying" VALUES ("5", "1:22.300");
INSERT INTO "races" VALUES ("1", "2009", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("2", "2009", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("3", "2010", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("4", "2009", "British Grand Prix");
INSERT INTO "races" VALUES ("5", "2011", "Spanish Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1:30:00.000", "210.500");
INSERT INTO "results" VALUES ("2", "1", "1:30:05.000", "212.100");
INSERT INTO "results" VALUES ("3", "1", "1:30:10.000", "209.800");
INSERT INTO "results" VALUES ("4", "2", "1:25:00.000", "180.000");
INSERT INTO "results" VALUES ("5", "3", "1:31:00.000", "211.000");
INSERT INTO "results" VALUES ("6", "1", "1:30:15.000", "211.200");
INSERT INTO "results" VALUES ("7", "4", "1:35:00.000", "220.000");
INSERT INTO "results" VALUES ("8", "5", "1:32:00.000", "210.000");