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,
"raceId" INT,
PRIMARY KEY ("qualifyId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"name" TEXT,
"date" DATE,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("year") REFERENCES "seasons"("year")
);

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

CREATE TABLE "seasons" (
"year" INT UNIQUE,
PRIMARY KEY ("year")
);



INSERT INTO "circuits" VALUES ("1", "Melbourne Grand Prix Circuit");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit");
INSERT INTO "circuits" VALUES ("3", "Bahrain International Circuit");
INSERT INTO "circuits" VALUES ("4", "Circuit de Catalunya");
INSERT INTO "circuits" VALUES ("5", "Circuit de Monaco");
INSERT INTO "circuits" VALUES ("6", "Nürburgring");
INSERT INTO "circuits" VALUES ("7", "Circuit Gilles Villeneuve");
INSERT INTO "circuits" VALUES ("8", "Indianapolis Motor Speedway");
INSERT INTO "circuits" VALUES ("9", "Magny-Cours");
INSERT INTO "circuits" VALUES ("10", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("11", "Hockenheimring");
INSERT INTO "circuits" VALUES ("12", "Hungaroring");
INSERT INTO "circuits" VALUES ("13", "Istanbul Park");
INSERT INTO "circuits" VALUES ("14", "Autodromo Nazionale Monza");
INSERT INTO "circuits" VALUES ("15", "Circuit de Spa-Francorchamps");
INSERT INTO "circuits" VALUES ("16", "Autódromo José Carlos Pace");
INSERT INTO "circuits" VALUES ("17", "Suzuka Circuit");
INSERT INTO "circuits" VALUES ("18", "Shanghai International Circuit");
INSERT INTO "seasons" VALUES ("2004");
INSERT INTO "seasons" VALUES ("2005");
INSERT INTO "seasons" VALUES ("2006");
INSERT INTO "seasons" VALUES ("2007");
INSERT INTO "seasons" VALUES ("2008");
INSERT INTO "races" VALUES ("1", "2005", "Australian Grand Prix", "2005-03-06");
INSERT INTO "races" VALUES ("2", "2005", "Malaysian Grand Prix", "2005-03-20");
INSERT INTO "races" VALUES ("3", "2005", "Bahrain Grand Prix", "2005-04-03");
INSERT INTO "races" VALUES ("4", "2005", "San Marino Grand Prix", "2005-04-24");
INSERT INTO "races" VALUES ("5", "2005", "Spanish Grand Prix", "2005-05-08");
INSERT INTO "races" VALUES ("6", "2005", "Monaco Grand Prix", "2005-05-22");
INSERT INTO "races" VALUES ("7", "2005", "European Grand Prix", "2005-05-29");
INSERT INTO "races" VALUES ("8", "2005", "Canadian Grand Prix", "2005-06-12");
INSERT INTO "races" VALUES ("9", "2005", "United States Grand Prix", "2005-06-19");
INSERT INTO "races" VALUES ("10", "2005", "French Grand Prix", "2005-07-03");
INSERT INTO "races" VALUES ("11", "2005", "British Grand Prix", "2005-07-10");
INSERT INTO "races" VALUES ("12", "2005", "German Grand Prix", "2005-07-24");
INSERT INTO "races" VALUES ("13", "2005", "Hungarian Grand Prix", "2005-07-31");
INSERT INTO "races" VALUES ("14", "2005", "Turkish Grand Prix", "2005-08-21");
INSERT INTO "races" VALUES ("15", "2005", "Italian Grand Prix", "2005-09-04");
INSERT INTO "races" VALUES ("16", "2005", "Belgian Grand Prix", "2005-09-11");
INSERT INTO "races" VALUES ("17", "2005", "Brazilian Grand Prix", "2005-09-25");
INSERT INTO "races" VALUES ("18", "2005", "Japanese Grand Prix", "2005-10-09");
INSERT INTO "races" VALUES ("19", "2005", "Chinese Grand Prix", "2005-10-16");
INSERT INTO "races" VALUES ("20", "2004", "Brazilian Grand Prix", "2004-10-24");
INSERT INTO "races" VALUES ("21", "2006", "Australian Grand Prix", "2006-03-12");
INSERT INTO "qualifying" VALUES ("1", "1");
INSERT INTO "qualifying" VALUES ("2", "2");
INSERT INTO "qualifying" VALUES ("3", "3");
INSERT INTO "qualifying" VALUES ("4", "4");
INSERT INTO "qualifying" VALUES ("5", "5");
INSERT INTO "qualifying" VALUES ("6", "6");
INSERT INTO "qualifying" VALUES ("7", "7");
INSERT INTO "qualifying" VALUES ("8", "8");
INSERT INTO "qualifying" VALUES ("9", "9");
INSERT INTO "qualifying" VALUES ("10", "10");
INSERT INTO "qualifying" VALUES ("11", "11");
INSERT INTO "qualifying" VALUES ("12", "12");
INSERT INTO "qualifying" VALUES ("13", "13");
INSERT INTO "qualifying" VALUES ("14", "14");
INSERT INTO "qualifying" VALUES ("15", "15");
INSERT INTO "qualifying" VALUES ("16", "16");
INSERT INTO "qualifying" VALUES ("17", "17");
INSERT INTO "qualifying" VALUES ("18", "18");
INSERT INTO "qualifying" VALUES ("19", "19");
INSERT INTO "qualifying" VALUES ("20", "20");
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");
INSERT INTO "results" VALUES ("6", "6");
INSERT INTO "results" VALUES ("7", "7");
INSERT INTO "results" VALUES ("8", "8");
INSERT INTO "results" VALUES ("9", "9");
INSERT INTO "results" VALUES ("10", "10");
INSERT INTO "results" VALUES ("11", "11");
INSERT INTO "results" VALUES ("12", "12");
INSERT INTO "results" VALUES ("13", "13");
INSERT INTO "results" VALUES ("14", "14");
INSERT INTO "results" VALUES ("15", "15");
INSERT INTO "results" VALUES ("16", "16");
INSERT INTO "results" VALUES ("17", "17");
INSERT INTO "results" VALUES ("18", "18");
INSERT INTO "results" VALUES ("19", "19");
INSERT INTO "results" VALUES ("20", "20");