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,
"position" INT,
PRIMARY KEY ("qualifyId")
);

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



INSERT INTO "circuits" VALUES ("1", "Melbourne Grand Prix Circuit", "Australia");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit", "Malaysia");
INSERT INTO "circuits" VALUES ("3", "Shanghai International Circuit", "China");
INSERT INTO "circuits" VALUES ("4", "Bahrain International Circuit", "Bahrain");
INSERT INTO "circuits" VALUES ("5", "Circuit de Barcelona-Catalunya", "Spain");
INSERT INTO "circuits" VALUES ("6", "Circuit de Monaco", "Monaco");
INSERT INTO "circuits" VALUES ("7", "Circuit Gilles Villeneuve", "Canada");
INSERT INTO "circuits" VALUES ("8", "Baku City Circuit", "Azerbaijan");
INSERT INTO "circuits" VALUES ("9", "Red Bull Ring", "Austria");
INSERT INTO "circuits" VALUES ("10", "Silverstone Circuit", "UK");
INSERT INTO "circuits" VALUES ("11", "Hungaroring", "Hungary");
INSERT INTO "circuits" VALUES ("12", "Circuit de Spa-Francorchamps", "Belgium");
INSERT INTO "circuits" VALUES ("13", "Autodromo Nazionale Monza", "Italy");
INSERT INTO "circuits" VALUES ("14", "Marina Bay Street Circuit", "Singapore");
INSERT INTO "circuits" VALUES ("15", "Suzuka International Racing Course", "Japan");
INSERT INTO "circuits" VALUES ("16", "Circuit of the Americas", "USA");
INSERT INTO "circuits" VALUES ("17", "Autódromo Hermanos Rodríguez", "Mexico");
INSERT INTO "circuits" VALUES ("18", "Autódromo José Carlos Pace", "Brazil");
INSERT INTO "circuits" VALUES ("19", "Yas Marina Circuit", "UAE");
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 "races" VALUES ("973", "2017", "1", "Australian Grand Prix", "2017-03-26", "06:00:00Z");
INSERT INTO "races" VALUES ("974", "2017", "3", "Chinese Grand Prix", "2017-04-09", "06:00:00Z");
INSERT INTO "races" VALUES ("975", "2017", "4", "Bahrain Grand Prix", "2017-04-16", "15:00:00Z");
INSERT INTO "races" VALUES ("976", "2017", "19", "Abu Dhabi Grand Prix", "2017-11-26", "13:00:00Z");
INSERT INTO "races" VALUES ("977", "2017", "5", "Spanish Grand Prix", "2017-05-14", "12:00:00Z");
INSERT INTO "races" VALUES ("978", "2017", "6", "Monaco Grand Prix", "2017-05-28", "12:00:00Z");
INSERT INTO "races" VALUES ("979", "2017", "7", "Canadian Grand Prix", "2017-06-11", "18:00:00Z");
INSERT INTO "races" VALUES ("980", "2017", "8", "Azerbaijan Grand Prix", "2017-06-25", "11:00:00Z");
INSERT INTO "races" VALUES ("981", "2017", "9", "Austrian Grand Prix", "2017-07-09", "12:00:00Z");
INSERT INTO "races" VALUES ("982", "2017", "10", "British Grand Prix", "2017-07-16", "12:00:00Z");
INSERT INTO "races" VALUES ("983", "2017", "11", "Hungarian Grand Prix", "2017-07-30", "12:00:00Z");
INSERT INTO "races" VALUES ("984", "2017", "12", "Belgian Grand Prix", "2017-08-27", "12:00:00Z");
INSERT INTO "races" VALUES ("985", "2017", "13", "Italian Grand Prix", "2017-09-03", "12:00:00Z");
INSERT INTO "races" VALUES ("986", "2017", "14", "Singapore Grand Prix", "2017-09-17", "12:00:00Z");
INSERT INTO "races" VALUES ("987", "2017", "2", "Malaysian Grand Prix", "2017-10-01", "07:00:00Z");
INSERT INTO "races" VALUES ("988", "2017", "15", "Japanese Grand Prix", "2017-10-08", "05:00:00Z");
INSERT INTO "races" VALUES ("989", "2017", "16", "United States Grand Prix", "2017-10-22", "19:00:00Z");
INSERT INTO "races" VALUES ("990", "2017", "17", "Mexican Grand Prix", "2017-10-29", "19:00:00Z");
INSERT INTO "races" VALUES ("991", "2017", "18", "Brazilian Grand Prix", "2017-11-12", "16:00:00Z");
INSERT INTO "races" VALUES ("992", "2016", "1", "Australian Grand Prix", "2016-03-20", "05:00:00Z");
INSERT INTO "races" VALUES ("993", "2018", "1", "Australian Grand Prix", "2018-03-25", "05:00:00Z");