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

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

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



INSERT INTO "circuits" VALUES ("1", "Albert Park Grand Prix Circuit", "Melbourne", "Australia");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit", "Kuala Lumpur", "Malaysia");
INSERT INTO "circuits" VALUES ("3", "Bahrain International Circuit", "Sakhir", "Bahrain");
INSERT INTO "circuits" VALUES ("4", "Circuit de Catalunya", "Montmelo", "Spain");
INSERT INTO "circuits" VALUES ("5", "Circuit de Monaco", "Monte-Carlo", "Monaco");
INSERT INTO "circuits" VALUES ("6", "Nürburgring", "Nürburg", "Germany");
INSERT INTO "circuits" VALUES ("7", "Circuit Gilles Villeneuve", "Montreal", "Canada");
INSERT INTO "circuits" VALUES ("8", "Indianapolis Motor Speedway", "Indianapolis", "USA");
INSERT INTO "circuits" VALUES ("9", "Circuit de Nevers Magny-Cours", "Magny Cours", "France");
INSERT INTO "circuits" VALUES ("10", "Silverstone Circuit", "Silverstone", "UK");
INSERT INTO "circuits" VALUES ("11", "Hockenheimring", "Hockenheim", "Germany");
INSERT INTO "circuits" VALUES ("12", "Hungaroring", "Budapest", "Hungary");
INSERT INTO "circuits" VALUES ("13", "Istanbul Park", "Istanbul", "Turkey");
INSERT INTO "circuits" VALUES ("14", "Autodromo Nazionale Monza", "Monza", "Italy");
INSERT INTO "circuits" VALUES ("15", "Circuit de Spa-Francorchamps", "Stavelot", "Belgium");
INSERT INTO "circuits" VALUES ("16", "Autódromo José Carlos Pace", "São Paulo", "Brazil");
INSERT INTO "circuits" VALUES ("17", "Suzuka Circuit", "Suzuka", "Japan");
INSERT INTO "circuits" VALUES ("18", "Shanghai International Circuit", "Shanghai", "China");
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 ("1", "2005", "1", "Australian Grand Prix", "2005-03-06");
INSERT INTO "races" VALUES ("2", "2005", "2", "Malaysian Grand Prix", "2005-03-20");
INSERT INTO "races" VALUES ("3", "2005", "3", "Bahrain Grand Prix", "2005-04-03");
INSERT INTO "races" VALUES ("4", "2005", "4", "Spanish Grand Prix", "2005-05-08");
INSERT INTO "races" VALUES ("5", "2005", "5", "Monaco Grand Prix", "2005-05-22");
INSERT INTO "races" VALUES ("6", "2005", "6", "European Grand Prix", "2005-05-29");
INSERT INTO "races" VALUES ("7", "2005", "7", "Canadian Grand Prix", "2005-06-12");
INSERT INTO "races" VALUES ("8", "2005", "8", "United States Grand Prix", "2005-06-19");
INSERT INTO "races" VALUES ("9", "2005", "9", "French Grand Prix", "2005-07-03");
INSERT INTO "races" VALUES ("10", "2005", "10", "British Grand Prix", "2005-07-10");
INSERT INTO "races" VALUES ("11", "2005", "11", "German Grand Prix", "2005-07-24");
INSERT INTO "races" VALUES ("12", "2005", "12", "Hungarian Grand Prix", "2005-07-31");
INSERT INTO "races" VALUES ("13", "2005", "13", "Turkish Grand Prix", "2005-08-21");
INSERT INTO "races" VALUES ("14", "2005", "14", "Italian Grand Prix", "2005-09-04");
INSERT INTO "races" VALUES ("15", "2005", "15", "Belgian Grand Prix", "2005-09-11");
INSERT INTO "races" VALUES ("16", "2005", "16", "Brazilian Grand Prix", "2005-09-25");
INSERT INTO "races" VALUES ("17", "2005", "17", "Japanese Grand Prix", "2005-10-09");
INSERT INTO "races" VALUES ("18", "2005", "18", "Chinese Grand Prix", "2005-10-16");
INSERT INTO "races" VALUES ("19", "2006", "1", "Australian Grand Prix", "2006-03-12");
INSERT INTO "races" VALUES ("20", "2006", "2", "Malaysian Grand Prix", "2006-03-19");