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

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



INSERT INTO "circuits" VALUES ("1", "Monza Circuit", "Monza", "Italy");
INSERT INTO "circuits" VALUES ("2", "Spa-Francorchamps", "Stavelot", "Belgium");
INSERT INTO "circuits" VALUES ("3", "Suzuka Circuit", "Suzuka", "Japan");
INSERT INTO "circuits" VALUES ("4", "Marina Bay Street Circuit", "Singapore", "Singapore");
INSERT INTO "circuits" VALUES ("5", "Circuit de Monaco", "Monte Carlo", "Monaco");
INSERT INTO "seasons" VALUES ("2004", "http://en.wikipedia.org/wiki/2004_Formula_One_season");
INSERT INTO "seasons" VALUES ("2005", "http://en.wikipedia.org/wiki/2005_Formula_One_season");
INSERT INTO "seasons" VALUES ("2006", "http://en.wikipedia.org/wiki/2006_Formula_One_season");
INSERT INTO "races" VALUES ("101", "2005", "13", "1", "Italian Grand Prix", "2005-09-11");
INSERT INTO "races" VALUES ("102", "2005", "14", "2", "Belgian Grand Prix", "2005-09-18");
INSERT INTO "races" VALUES ("103", "2005", "15", "3", "Japanese Grand Prix", "2005-10-09");
INSERT INTO "races" VALUES ("104", "2005", "12", "4", "Singapore Grand Prix", "2005-09-25");
INSERT INTO "races" VALUES ("105", "2004", "13", "5", "Monaco Grand Prix", "2004-05-23");
INSERT INTO "races" VALUES ("106", "2006", "13", "1", "Italian Grand Prix", "2006-09-10");
INSERT INTO "races" VALUES ("107", "2005", "11", "5", "Monaco Grand Prix", "2005-05-29");