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,
"lat" FLOAT,
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 ("year") REFERENCES "seasons"("year"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

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



INSERT INTO "circuits" VALUES ("1", "Circuit de Barcelona-Catalunya", "Montmelo", "Spain", "41.57");
INSERT INTO "circuits" VALUES ("2", "Monza", "Monza", "Italy", "45.61");
INSERT INTO "circuits" VALUES ("3", "Silverstone Circuit", "Silverstone", "UK", "52.07");
INSERT INTO "circuits" VALUES ("4", "Indianapolis Motor Speedway", "Indianapolis", "USA", "39.79");
INSERT INTO "circuits" VALUES ("5", "Circuit Gilles Villeneuve", "Montreal", "Canada", "45.5");
INSERT INTO "circuits" VALUES ("6", "Suzuka Circuit", "Suzuka", "Japan", "34.84");
INSERT INTO "circuits" VALUES ("7", "Shanghai International Circuit", "Shanghai", "China", "31.33");
INSERT INTO "circuits" VALUES ("8", "Bahrain International Circuit", "Sakhir", "Bahrain", "26.03");
INSERT INTO "circuits" VALUES ("9", "Hungaroring", "Mogyorod", "Hungary", "47.58");
INSERT INTO "circuits" VALUES ("10", "Circuit of the Americas", "Austin", "USA", "30.13");
INSERT INTO "circuits" VALUES ("11", "Phoenix Street Circuit", "Phoenix", "USA", "33.45");
INSERT INTO "circuits" VALUES ("12", "Watkins Glen", "Watkins Glen", "USA", "42.33");
INSERT INTO "circuits" VALUES ("13", "Long Beach Street Circuit", "Long Beach", "USA", "33.76");
INSERT INTO "circuits" VALUES ("14", "Detroit Street Circuit", "Detroit", "USA", "42.33");
INSERT INTO "constructors" VALUES ("1", "Ferrari");
INSERT INTO "constructors" VALUES ("2", "McLaren");
INSERT INTO "constructors" VALUES ("3", "Mercedes");
INSERT INTO "constructors" VALUES ("4", "Red Bull");
INSERT INTO "constructors" VALUES ("5", "Renault");
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 "races" VALUES ("1", "2006", "4", "United States Grand Prix", "2006-07-02");
INSERT INTO "races" VALUES ("2", "2006", "1", "Spanish Grand Prix", "2006-05-14");
INSERT INTO "races" VALUES ("3", "2006", "2", "Italian Grand Prix", "2006-09-10");
INSERT INTO "races" VALUES ("4", "2006", "3", "British Grand Prix", "2006-06-11");
INSERT INTO "races" VALUES ("5", "2005", "4", "United States Grand Prix", "2005-06-19");
INSERT INTO "races" VALUES ("6", "2006", "5", "Canadian Grand Prix", "2006-06-25");
INSERT INTO "races" VALUES ("7", "2006", "10", "United States Grand Prix COTA", "2006-11-05");
INSERT INTO "races" VALUES ("8", "2006", "11", "Phoenix Grand Prix", "2006-03-12");
INSERT INTO "races" VALUES ("9", "2006", "12", "Watkins Glen Grand Prix", "2006-08-20");
INSERT INTO "races" VALUES ("10", "2006", "13", "Long Beach Grand Prix", "2006-04-09");
INSERT INTO "races" VALUES ("11", "2006", "14", "Detroit Grand Prix", "2006-06-04");
INSERT INTO "races" VALUES ("12", "2007", "4", "United States Grand Prix", "2007-06-17");
INSERT INTO "races" VALUES ("13", "2006", "4", "Indianapolis F1 Test", "2006-05-01");
INSERT INTO "races" VALUES ("14", "2006", "10", "US F1 Challenge Race", "2006-10-22");