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

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

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"nationality" TEXT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"name" TEXT,
PRIMARY KEY ("raceId")
);

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);



INSERT INTO "circuits" VALUES ("1", "Melbourne Grand Prix Circuit");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit");
INSERT INTO "circuits" VALUES ("3", "Bahrain International Circuit");
INSERT INTO "circuits" VALUES ("4", "Shanghai International Circuit");
INSERT INTO "circuits" VALUES ("5", "Circuit de Catalunya");
INSERT INTO "circuits" VALUES ("6", "Circuit de Monaco");
INSERT INTO "circuits" VALUES ("7", "Circuit Gilles Villeneuve");
INSERT INTO "circuits" VALUES ("8", "Circuit de Nevers Magny-Cours");
INSERT INTO "circuits" VALUES ("9", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("10", "Hockenheimring");
INSERT INTO "constructors" VALUES ("1", "McLaren");
INSERT INTO "constructors" VALUES ("2", "Ferrari");
INSERT INTO "constructors" VALUES ("3", "BMW Sauber");
INSERT INTO "constructors" VALUES ("4", "Renault");
INSERT INTO "constructors" VALUES ("5", "Williams");
INSERT INTO "constructors" VALUES ("6", "Red Bull");
INSERT INTO "constructors" VALUES ("7", "Toyota");
INSERT INTO "constructors" VALUES ("8", "Toro Rosso");
INSERT INTO "constructors" VALUES ("9", "Honda");
INSERT INTO "constructors" VALUES ("10", "Force India");
INSERT INTO "drivers" VALUES ("1", "Lewis", "British");
INSERT INTO "drivers" VALUES ("2", "Felipe", "Brazilian");
INSERT INTO "drivers" VALUES ("3", "Kimi", "Finnish");
INSERT INTO "drivers" VALUES ("4", "Robert", "Polish");
INSERT INTO "drivers" VALUES ("5", "Nick", "German");
INSERT INTO "drivers" VALUES ("6", "Heikki", "Finnish");
INSERT INTO "drivers" VALUES ("7", "Fernando", "Spanish");
INSERT INTO "drivers" VALUES ("8", "Jarno", "Italian");
INSERT INTO "drivers" VALUES ("9", "Mark", "Australian");
INSERT INTO "drivers" VALUES ("10", "David", "British");
INSERT INTO "drivers" VALUES ("11", "Sebastian", "German");
INSERT INTO "drivers" VALUES ("12", "Nelson", "Brazilian");
INSERT INTO "drivers" VALUES ("13", "Rubens", "Brazilian");
INSERT INTO "drivers" VALUES ("14", "Jenson", "British");
INSERT INTO "drivers" VALUES ("15", "Giancarlo", "Italian");
INSERT INTO "drivers" VALUES ("16", "Adrian", "German");
INSERT INTO "drivers" VALUES ("17", "Kazuki", "Japanese");
INSERT INTO "drivers" VALUES ("18", "Sebastien", "French");
INSERT INTO "drivers" VALUES ("19", "Timo", "German");
INSERT INTO "drivers" VALUES ("20", "Anthony", "British");
INSERT INTO "races" VALUES ("1", "2008", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "2008", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("3", "2008", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("4", "2008", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("5", "2009", "Australian Grand Prix");
INSERT INTO "races" VALUES ("6", "2007", "Australian Grand Prix");
INSERT INTO "races" VALUES ("7", "2008", "Monaco Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1");
INSERT INTO "results" VALUES ("2", "1", "4");
INSERT INTO "results" VALUES ("3", "1", "5");
INSERT INTO "results" VALUES ("4", "1", "6");
INSERT INTO "results" VALUES ("5", "1", "7");
INSERT INTO "results" VALUES ("6", "1", "8");
INSERT INTO "results" VALUES ("7", "1", "9");
INSERT INTO "results" VALUES ("8", "1", "10");
INSERT INTO "results" VALUES ("9", "1", "14");
INSERT INTO "results" VALUES ("10", "1", "17");
INSERT INTO "results" VALUES ("11", "1", "20");
INSERT INTO "results" VALUES ("12", "2", "3");
INSERT INTO "results" VALUES ("13", "2", "2");
INSERT INTO "results" VALUES ("14", "5", "14");
INSERT INTO "results" VALUES ("15", "6", "1");
INSERT INTO "results" VALUES ("16", "7", "1");
INSERT INTO "results" VALUES ("17", "7", "3");