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", "Albert Park Grand Prix Circuit", "Melbourne", "Australia", "-37.8497");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit", "Kuala Lumpur", "Malaysia", "2.76083");
INSERT INTO "circuits" VALUES ("3", "Bahrain International Circuit", "Sakhir", "Bahrain", "26.0325");
INSERT INTO "circuits" VALUES ("4", "Circuit de Barcelona-Catalunya", "Montmeló", "Spain", "41.57");
INSERT INTO "circuits" VALUES ("5", "Circuit de Monaco", "Monte-Carlo", "Monaco", "43.7347");
INSERT INTO "circuits" VALUES ("6", "Circuit Gilles Villeneuve", "Montreal", "Canada", "45.5");
INSERT INTO "circuits" VALUES ("7", "Silverstone Circuit", "Silverstone", "UK", "52.0786");
INSERT INTO "circuits" VALUES ("8", "Hockenheimring", "Hockenheim", "Germany", "49.3278");
INSERT INTO "circuits" VALUES ("9", "Hungaroring", "Mogyoród", "Hungary", "47.5789");
INSERT INTO "circuits" VALUES ("10", "Circuit de Spa-Francorchamps", "Spa", "Belgium", "50.4367");
INSERT INTO "circuits" VALUES ("11", "Autodromo Nazionale di Monza", "Monza", "Italy", "45.6156");
INSERT INTO "circuits" VALUES ("12", "Indianapolis Motor Speedway", "Indianapolis", "USA", "39.795");
INSERT INTO "circuits" VALUES ("13", "Suzuka Circuit", "Suzuka", "Japan", "34.8431");
INSERT INTO "circuits" VALUES ("14", "Interlagos", "São Paulo", "Brazil", "-23.7036");
INSERT INTO "circuits" VALUES ("15", "Shanghai International Circuit", "Shanghai", "China", "31.3389");
INSERT INTO "circuits" VALUES ("16", "Circuit of the Americas", "Austin", "USA", "30.1328");
INSERT INTO "circuits" VALUES ("17", "Phoenix Street Circuit", "Phoenix", "USA", "33.4484");
INSERT INTO "circuits" VALUES ("18", "Watkins Glen", "Watkins Glen", "USA", "42.3369");
INSERT INTO "circuits" VALUES ("19", "Long Beach", "Long Beach", "USA", "33.767");
INSERT INTO "circuits" VALUES ("20", "Detroit Street Circuit", "Detroit", "USA", "42.3314");
INSERT INTO "constructors" VALUES ("1", "Ferrari");
INSERT INTO "constructors" VALUES ("2", "McLaren");
INSERT INTO "constructors" VALUES ("3", "Williams");
INSERT INTO "constructors" VALUES ("4", "Renault");
INSERT INTO "constructors" VALUES ("5", "Red Bull");
INSERT INTO "constructors" VALUES ("6", "Mercedes");
INSERT INTO "races" VALUES ("1", "2006", "1", "Australian Grand Prix", "2006-04-02");
INSERT INTO "races" VALUES ("2", "2006", "2", "Malaysian Grand Prix", "2006-03-19");
INSERT INTO "races" VALUES ("3", "2006", "3", "Bahrain Grand Prix", "2006-03-12");
INSERT INTO "races" VALUES ("4", "2006", "4", "Spanish Grand Prix", "2006-05-14");
INSERT INTO "races" VALUES ("5", "2006", "5", "Monaco Grand Prix", "2006-05-28");
INSERT INTO "races" VALUES ("6", "2006", "6", "Canadian Grand Prix", "2006-06-25");
INSERT INTO "races" VALUES ("7", "2006", "7", "British Grand Prix", "2006-06-11");
INSERT INTO "races" VALUES ("8", "2006", "8", "German Grand Prix", "2006-07-30");
INSERT INTO "races" VALUES ("9", "2006", "9", "Hungarian Grand Prix", "2006-08-06");
INSERT INTO "races" VALUES ("10", "2006", "10", "Belgian Grand Prix", "2006-09-10");
INSERT INTO "races" VALUES ("11", "2006", "11", "Italian Grand Prix", "2006-09-10");
INSERT INTO "races" VALUES ("12", "2006", "12", "United States Grand Prix", "2006-07-02");
INSERT INTO "races" VALUES ("13", "2006", "13", "Japanese Grand Prix", "2006-10-08");
INSERT INTO "races" VALUES ("14", "2006", "14", "Brazilian Grand Prix", "2006-10-22");
INSERT INTO "races" VALUES ("15", "2006", "15", "Chinese Grand Prix", "2006-10-01");
INSERT INTO "races" VALUES ("16", "2005", "12", "United States Grand Prix", "2005-06-19");
INSERT INTO "races" VALUES ("17", "2007", "12", "United States Grand Prix", "2007-06-17");
INSERT INTO "races" VALUES ("18", "2006", "16", "United States Grand Prix West", "2006-04-09");
INSERT INTO "races" VALUES ("19", "2006", "17", "Phoenix Grand Prix", "2006-03-26");
INSERT INTO "races" VALUES ("20", "2006", "18", "Watkins Glen Grand Prix", "2006-05-07");
INSERT INTO "races" VALUES ("21", "2006", "19", "Long Beach Grand Prix", "2006-04-16");
INSERT INTO "races" VALUES ("22", "2006", "20", "Detroit Grand Prix", "2006-06-04");
INSERT INTO "races" VALUES ("23", "2007", "16", "United States Grand Prix", "2007-09-23");
INSERT INTO "seasons" VALUES ("2006");
INSERT INTO "seasons" VALUES ("2005");
INSERT INTO "seasons" VALUES ("2007");
INSERT INTO "seasons" VALUES ("2008");
INSERT INTO "seasons" VALUES ("2009");