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,
"country" 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,
"circuitId" INT,
"date" DATE,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("year") REFERENCES "seasons"("year"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

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



INSERT INTO "circuits" VALUES ("1", "Albert Park Grand Prix Circuit", "Australia");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit", "Malaysia");
INSERT INTO "circuits" VALUES ("3", "Bahrain International Circuit", "Bahrain");
INSERT INTO "circuits" VALUES ("4", "Circuit de Catalunya", "Spain");
INSERT INTO "circuits" VALUES ("5", "Circuit de Monaco", "Monaco");
INSERT INTO "circuits" VALUES ("6", "Circuit Gilles Villeneuve", "Canada");
INSERT INTO "circuits" VALUES ("7", "Silverstone Circuit", "UK");
INSERT INTO "circuits" VALUES ("8", "Hockenheimring", "Germany");
INSERT INTO "circuits" VALUES ("9", "Hungaroring", "Hungary");
INSERT INTO "circuits" VALUES ("10", "Spa-Francorchamps", "Belgium");
INSERT INTO "circuits" VALUES ("11", "Autodromo Nazionale Monza", "Italy");
INSERT INTO "circuits" VALUES ("12", "Marina Bay Street Circuit", "Singapore");
INSERT INTO "circuits" VALUES ("13", "Suzuka Circuit", "Japan");
INSERT INTO "circuits" VALUES ("14", "Interlagos", "Brazil");
INSERT INTO "circuits" VALUES ("15", "Yas Marina Circuit", "UAE");
INSERT INTO "circuits" VALUES ("16", "Shanghai International Circuit", "China");
INSERT INTO "circuits" VALUES ("17", "Istanbul Park", "Turkey");
INSERT INTO "circuits" VALUES ("18", "Nürburgring", "Germany");
INSERT INTO "circuits" VALUES ("19", "Circuit of the Americas", "USA");
INSERT INTO "circuits" VALUES ("20", "Sochi Autodrom", "Russia");
INSERT INTO "seasons" VALUES ("2000");
INSERT INTO "seasons" VALUES ("2001");
INSERT INTO "seasons" VALUES ("2002");
INSERT INTO "seasons" VALUES ("2003");
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 "seasons" VALUES ("2009");
INSERT INTO "seasons" VALUES ("2010");
INSERT INTO "seasons" VALUES ("2011");
INSERT INTO "seasons" VALUES ("2012");
INSERT INTO "seasons" VALUES ("2013");
INSERT INTO "seasons" VALUES ("2014");
INSERT INTO "seasons" VALUES ("2015");
INSERT INTO "races" VALUES ("1", "2000", "1", "2000-03-12");
INSERT INTO "races" VALUES ("2", "2000", "2", "2000-03-19");
INSERT INTO "races" VALUES ("3", "2000", "13", "2000-10-08");
INSERT INTO "races" VALUES ("4", "2001", "1", "2001-03-04");
INSERT INTO "races" VALUES ("5", "2001", "2", "2001-03-18");
INSERT INTO "races" VALUES ("6", "2001", "4", "2001-04-29");
INSERT INTO "races" VALUES ("7", "2002", "1", "2002-03-03");
INSERT INTO "races" VALUES ("8", "2002", "2", "2002-03-17");
INSERT INTO "races" VALUES ("9", "2002", "5", "2002-05-26");
INSERT INTO "races" VALUES ("10", "2003", "1", "2003-03-09");
INSERT INTO "races" VALUES ("11", "2003", "2", "2003-03-23");
INSERT INTO "races" VALUES ("12", "2003", "6", "2003-06-15");
INSERT INTO "races" VALUES ("13", "2003", "7", "2003-07-20");
INSERT INTO "races" VALUES ("14", "2004", "1", "2004-03-07");
INSERT INTO "races" VALUES ("15", "2004", "2", "2004-03-21");
INSERT INTO "races" VALUES ("16", "2004", "3", "2004-04-04");
INSERT INTO "races" VALUES ("17", "2004", "4", "2004-05-09");
INSERT INTO "races" VALUES ("18", "2004", "5", "2004-05-23");
INSERT INTO "races" VALUES ("19", "2005", "1", "2005-03-06");
INSERT INTO "races" VALUES ("20", "2005", "2", "2005-03-20");
INSERT INTO "races" VALUES ("21", "2005", "3", "2005-04-03");
INSERT INTO "races" VALUES ("22", "2005", "4", "2005-05-08");
INSERT INTO "races" VALUES ("23", "2005", "5", "2005-05-22");
INSERT INTO "races" VALUES ("24", "2005", "6", "2005-06-12");
INSERT INTO "races" VALUES ("25", "2006", "1", "2006-03-12");
INSERT INTO "races" VALUES ("26", "2006", "2", "2006-03-19");
INSERT INTO "races" VALUES ("27", "2006", "3", "2006-04-02");
INSERT INTO "races" VALUES ("28", "2006", "4", "2006-05-14");
INSERT INTO "races" VALUES ("29", "2006", "5", "2006-05-28");
INSERT INTO "races" VALUES ("30", "2006", "6", "2006-06-25");
INSERT INTO "races" VALUES ("31", "2006", "7", "2006-08-06");
INSERT INTO "races" VALUES ("32", "2007", "1", "2007-03-18");
INSERT INTO "races" VALUES ("33", "2007", "2", "2007-04-08");
INSERT INTO "races" VALUES ("34", "2007", "3", "2007-04-15");
INSERT INTO "races" VALUES ("35", "2007", "4", "2007-05-13");
INSERT INTO "races" VALUES ("36", "2007", "5", "2007-05-27");
INSERT INTO "races" VALUES ("37", "2007", "6", "2007-06-10");
INSERT INTO "races" VALUES ("38", "2007", "7", "2007-07-08");
INSERT INTO "races" VALUES ("39", "2007", "8", "2007-07-22");
INSERT INTO "races" VALUES ("40", "2008", "1", "2008-03-16");
INSERT INTO "races" VALUES ("41", "2008", "2", "2008-03-23");
INSERT INTO "races" VALUES ("42", "2008", "3", "2008-04-06");
INSERT INTO "races" VALUES ("43", "2008", "4", "2008-04-27");
INSERT INTO "races" VALUES ("44", "2008", "5", "2008-05-25");
INSERT INTO "races" VALUES ("45", "2008", "6", "2008-06-08");
INSERT INTO "races" VALUES ("46", "2008", "7", "2008-07-06");
INSERT INTO "races" VALUES ("47", "2008", "8", "2008-07-20");
INSERT INTO "races" VALUES ("48", "2008", "9", "2008-08-03");
INSERT INTO "races" VALUES ("49", "2008", "10", "2008-09-07");
INSERT INTO "races" VALUES ("50", "2008", "11", "2008-09-14");
INSERT INTO "races" VALUES ("51", "2008", "12", "2008-09-28");
INSERT INTO "races" VALUES ("52", "2009", "1", "2009-03-29");
INSERT INTO "races" VALUES ("53", "2009", "2", "2009-04-05");
INSERT INTO "races" VALUES ("54", "2009", "3", "2009-04-19");
INSERT INTO "races" VALUES ("55", "2009", "4", "2009-05-10");
INSERT INTO "races" VALUES ("56", "2009", "5", "2009-05-24");
INSERT INTO "races" VALUES ("57", "2009", "6", "2009-06-07");
INSERT INTO "races" VALUES ("58", "2009", "7", "2009-06-21");
INSERT INTO "races" VALUES ("59", "2009", "8", "2009-07-12");
INSERT INTO "races" VALUES ("60", "2009", "9", "2009-07-26");
INSERT INTO "races" VALUES ("61", "2009", "10", "2009-08-23");
INSERT INTO "races" VALUES ("62", "2009", "11", "2009-09-06");
INSERT INTO "races" VALUES ("63", "2009", "12", "2009-09-27");
INSERT INTO "races" VALUES ("64", "2009", "13", "2009-10-04");
INSERT INTO "races" VALUES ("65", "2009", "14", "2009-10-18");
INSERT INTO "races" VALUES ("66", "2009", "15", "2009-11-01");
INSERT INTO "races" VALUES ("67", "2009", "14", "2009-10-04");
INSERT INTO "races" VALUES ("68", "2010", "3", "2010-03-14");
INSERT INTO "races" VALUES ("69", "2010", "1", "2010-03-28");
INSERT INTO "races" VALUES ("70", "2010", "2", "2010-04-04");
INSERT INTO "races" VALUES ("71", "2010", "16", "2010-04-18");
INSERT INTO "races" VALUES ("72", "2010", "4", "2010-05-09");
INSERT INTO "races" VALUES ("73", "2010", "5", "2010-05-16");
INSERT INTO "races" VALUES ("74", "2010", "17", "2010-05-30");
INSERT INTO "races" VALUES ("75", "2010", "6", "2010-06-13");
INSERT INTO "races" VALUES ("76", "2010", "18", "2010-07-25");
INSERT INTO "races" VALUES ("77", "2010", "9", "2010-08-01");
INSERT INTO "races" VALUES ("78", "2010", "10", "2010-08-29");
INSERT INTO "races" VALUES ("79", "2010", "11", "2010-09-12");
INSERT INTO "races" VALUES ("80", "2010", "12", "2010-09-26");
INSERT INTO "races" VALUES ("81", "2010", "13", "2010-10-10");
INSERT INTO "races" VALUES ("82", "2010", "14", "2010-11-07");
INSERT INTO "races" VALUES ("83", "2010", "15", "2010-11-14");
INSERT INTO "races" VALUES ("84", "2011", "1", "2011-03-27");
INSERT INTO "races" VALUES ("85", "2012", "1", "2012-03-18");
INSERT INTO "races" VALUES ("86", "2013", "1", "2013-03-17");
INSERT INTO "races" VALUES ("87", "2014", "1", "2014-03-16");
INSERT INTO "races" VALUES ("88", "2015", "1", "2015-03-15");
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 "qualifying" VALUES ("21", "21");
INSERT INTO "qualifying" VALUES ("22", "22");
INSERT INTO "qualifying" VALUES ("23", "23");
INSERT INTO "qualifying" VALUES ("24", "24");
INSERT INTO "qualifying" VALUES ("25", "25");
INSERT INTO "qualifying" VALUES ("26", "26");
INSERT INTO "qualifying" VALUES ("27", "27");
INSERT INTO "qualifying" VALUES ("28", "28");
INSERT INTO "qualifying" VALUES ("29", "29");
INSERT INTO "qualifying" VALUES ("30", "30");
INSERT INTO "qualifying" VALUES ("31", "31");
INSERT INTO "qualifying" VALUES ("32", "32");
INSERT INTO "qualifying" VALUES ("33", "33");
INSERT INTO "qualifying" VALUES ("34", "34");
INSERT INTO "qualifying" VALUES ("35", "35");
INSERT INTO "qualifying" VALUES ("36", "36");
INSERT INTO "qualifying" VALUES ("37", "37");
INSERT INTO "qualifying" VALUES ("38", "38");
INSERT INTO "qualifying" VALUES ("39", "39");
INSERT INTO "qualifying" VALUES ("40", "40");
INSERT INTO "qualifying" VALUES ("41", "41");
INSERT INTO "qualifying" VALUES ("42", "42");
INSERT INTO "qualifying" VALUES ("43", "43");
INSERT INTO "qualifying" VALUES ("44", "44");
INSERT INTO "qualifying" VALUES ("45", "45");
INSERT INTO "qualifying" VALUES ("46", "46");
INSERT INTO "qualifying" VALUES ("47", "47");
INSERT INTO "qualifying" VALUES ("48", "48");
INSERT INTO "qualifying" VALUES ("49", "49");
INSERT INTO "qualifying" VALUES ("50", "50");
INSERT INTO "qualifying" VALUES ("51", "51");
INSERT INTO "qualifying" VALUES ("52", "52");
INSERT INTO "qualifying" VALUES ("53", "53");
INSERT INTO "qualifying" VALUES ("54", "54");
INSERT INTO "qualifying" VALUES ("55", "55");
INSERT INTO "qualifying" VALUES ("56", "56");
INSERT INTO "qualifying" VALUES ("57", "57");
INSERT INTO "qualifying" VALUES ("58", "58");
INSERT INTO "qualifying" VALUES ("59", "59");
INSERT INTO "qualifying" VALUES ("60", "60");
INSERT INTO "qualifying" VALUES ("61", "61");
INSERT INTO "qualifying" VALUES ("62", "62");
INSERT INTO "qualifying" VALUES ("63", "63");
INSERT INTO "qualifying" VALUES ("64", "64");
INSERT INTO "qualifying" VALUES ("65", "65");
INSERT INTO "qualifying" VALUES ("66", "66");
INSERT INTO "qualifying" VALUES ("67", "67");
INSERT INTO "qualifying" VALUES ("68", "68");
INSERT INTO "qualifying" VALUES ("69", "69");
INSERT INTO "qualifying" VALUES ("70", "70");
INSERT INTO "qualifying" VALUES ("71", "71");
INSERT INTO "qualifying" VALUES ("72", "72");
INSERT INTO "qualifying" VALUES ("73", "73");
INSERT INTO "qualifying" VALUES ("74", "74");
INSERT INTO "qualifying" VALUES ("75", "75");
INSERT INTO "qualifying" VALUES ("76", "76");
INSERT INTO "qualifying" VALUES ("77", "77");
INSERT INTO "qualifying" VALUES ("78", "78");
INSERT INTO "qualifying" VALUES ("79", "79");
INSERT INTO "qualifying" VALUES ("80", "80");
INSERT INTO "qualifying" VALUES ("81", "81");
INSERT INTO "qualifying" VALUES ("82", "82");
INSERT INTO "qualifying" VALUES ("83", "83");
INSERT INTO "qualifying" VALUES ("84", "84");
INSERT INTO "qualifying" VALUES ("85", "85");
INSERT INTO "qualifying" VALUES ("86", "86");
INSERT INTO "qualifying" VALUES ("87", "87");
INSERT INTO "qualifying" VALUES ("88", "88");