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 "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"surname" 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,
"position" INT,
"time" TEXT,
"fastestLap" INT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);



INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Jenson", "Button");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Kimi", "Raikkonen");
INSERT INTO "drivers" VALUES ("6", "Felipe", "Massa");
INSERT INTO "drivers" VALUES ("7", "Mark", "Webber");
INSERT INTO "drivers" VALUES ("8", "Rubens", "Barrichello");
INSERT INTO "drivers" VALUES ("9", "Nico", "Rosberg");
INSERT INTO "drivers" VALUES ("10", "Robert", "Kubica");
INSERT INTO "races" VALUES ("1", "2009", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "2009", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("3", "2009", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("4", "2009", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("5", "2009", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("6", "2009", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("7", "2009", "Turkish Grand Prix");
INSERT INTO "races" VALUES ("8", "2009", "British Grand Prix");
INSERT INTO "races" VALUES ("9", "2009", "German Grand Prix");
INSERT INTO "races" VALUES ("10", "2009", "Hungarian Grand Prix");
INSERT INTO "races" VALUES ("11", "2010", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("12", "2008", "Japanese Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "3", "1", "1:34:15.782", "45");
INSERT INTO "results" VALUES ("2", "1", "8", "2", "1:34:16.500", "42");
INSERT INTO "results" VALUES ("3", "1", "2", "3", "1:34:17.123", "48");
INSERT INTO "results" VALUES ("4", "2", "3", "1", "1:25:38.800", "30");
INSERT INTO "results" VALUES ("5", "2", "1", "2", "1:25:39.100", "32");
INSERT INTO "results" VALUES ("6", "3", "2", "1", "1:57:43.400", "50");
INSERT INTO "results" VALUES ("7", "3", "1", "2", "1:57:44.000", "51");
INSERT INTO "results" VALUES ("8", "4", "3", "6", "1:35:00.000", "25");
INSERT INTO "results" VALUES ("9", "4", "2", "1", "1:31:48.400", "35");
INSERT INTO "results" VALUES ("10", "5", "3", "1", "1:39:42.700", "40");
INSERT INTO "results" VALUES ("11", "6", "3", "1", "1:40:44.200", "60");
INSERT INTO "results" VALUES ("12", "7", "3", "1", "1:26:24.700", "38");
INSERT INTO "results" VALUES ("13", "8", "3", "1", "1:22:34.500", "44");
INSERT INTO "results" VALUES ("14", "9", "3", "1", "1:31:56.800", "33");
INSERT INTO "results" VALUES ("15", "10", "3", "1", "1:38:46.300", "37");
INSERT INTO "results" VALUES ("16", "10", "1", "2", "1:38:47.000", "39");
INSERT INTO "results" VALUES ("17", "11", "2", "1", "1:30:00.000", "41");
INSERT INTO "results" VALUES ("18", "12", "1", "1", "1:28:00.000", "43");
INSERT INTO "results" VALUES ("19", "1", "4", "4", "1:34:18.000", "46");
INSERT INTO "results" VALUES ("20", "1", "5", "5", "1:34:19.000", "47");
INSERT INTO "results" VALUES ("21", "1", "6", "6", "1:34:20.000", "49");
INSERT INTO "results" VALUES ("22", "1", "7", "7", "1:34:21.000", "50");
INSERT INTO "results" VALUES ("23", "1", "9", "8", "1:34:22.000", "51");
INSERT INTO "results" VALUES ("24", "1", "10", "9", "1:34:23.000", "52");