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

CREATE TABLE "constructors" (
"constructorId" INT,
"name" TEXT,
PRIMARY KEY ("constructorId")
);

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", "Circuit de Barcelona-Catalunya", "Montmeló", "Spain", "50");
INSERT INTO "circuits" VALUES ("2", "Silverstone Circuit", "Silverstone", "United Kingdom", "150");
INSERT INTO "circuits" VALUES ("3", "Monza Circuit", "Monza", "Italy", "100");
INSERT INTO "circuits" VALUES ("4", "Circuit Gilles Villeneuve", "Montreal", "Canada", "30");
INSERT INTO "circuits" VALUES ("5", "Suzuka Circuit", "Suzuka", "Japan", "70");
INSERT INTO "constructors" VALUES ("1", "Ferrari");
INSERT INTO "constructors" VALUES ("2", "McLaren");
INSERT INTO "constructors" VALUES ("3", "Red Bull Racing");
INSERT INTO "constructors" VALUES ("4", "Mercedes");
INSERT INTO "constructors" VALUES ("5", "Renault");
INSERT INTO "races" VALUES ("101", "2009", "1", "Spanish Grand Prix", "2009-05-10");
INSERT INTO "races" VALUES ("102", "2009", "2", "British Grand Prix", "2009-07-12");
INSERT INTO "races" VALUES ("103", "2009", "3", "Italian Grand Prix", "2009-09-13");
INSERT INTO "races" VALUES ("104", "2008", "1", "Spanish Grand Prix", "2008-05-11");
INSERT INTO "races" VALUES ("105", "2010", "1", "Spanish Grand Prix", "2010-05-09");
INSERT INTO "races" VALUES ("106", "2009", "4", "Canadian Grand Prix", "2009-06-07");
INSERT INTO "races" VALUES ("107", "2009", "5", "Japanese Grand Prix", "2009-10-04");