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 "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"time" TEXT,
PRIMARY KEY ("raceId", "driverId", "lap")
);

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,
"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,
"positionOrder" INT,
"time" TEXT,
"milliseconds" INT,
"statusId" INT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId"),
FOREIGN KEY ("statusId") REFERENCES "status"("statusId")
);

CREATE TABLE "status" (
"statusId" INT UNIQUE,
"status" TEXT,
PRIMARY KEY ("statusId")
);



INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Disqualified");
INSERT INTO "status" VALUES ("3", "Accident");
INSERT INTO "status" VALUES ("4", "Engine");
INSERT INTO "status" VALUES ("5", "Gearbox");
INSERT INTO "status" VALUES ("6", "Collision");
INSERT INTO "status" VALUES ("7", "Spun off");
INSERT INTO "status" VALUES ("8", "Withdrew");
INSERT INTO "status" VALUES ("9", "Not classified");
INSERT INTO "status" VALUES ("10", "Retired");
INSERT INTO "races" VALUES ("1", "2008", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "2008", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("3", "2007", "Australian Grand Prix");
INSERT INTO "races" VALUES ("4", "2009", "Australian Grand Prix");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Nick", "Heidfeld");
INSERT INTO "drivers" VALUES ("3", "Nico", "Rosberg");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Kazuki", "Nakajima");
INSERT INTO "drivers" VALUES ("6", "Rubens", "Barrichello");
INSERT INTO "drivers" VALUES ("7", "Kimi", "Raikkonen");
INSERT INTO "drivers" VALUES ("8", "Felipe", "Massa");
INSERT INTO "drivers" VALUES ("9", "Giancarlo", "Fisichella");
INSERT INTO "drivers" VALUES ("10", "Jarno", "Trulli");
INSERT INTO "drivers" VALUES ("11", "Timo", "Glock");
INSERT INTO "drivers" VALUES ("12", "Takuma", "Sato");
INSERT INTO "drivers" VALUES ("13", "Nelson", "Piquet Jr.");
INSERT INTO "drivers" VALUES ("14", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("15", "Mark", "Webber");
INSERT INTO "drivers" VALUES ("16", "David", "Coulthard");
INSERT INTO "drivers" VALUES ("17", "Adrian", "Sutil");
INSERT INTO "drivers" VALUES ("18", "Anthony", "Davidson");
INSERT INTO "drivers" VALUES ("19", "Robert", "Kubica");
INSERT INTO "drivers" VALUES ("20", "Jenson", "Button");
INSERT INTO "drivers" VALUES ("21", "Heikki", "Kovalainen");
INSERT INTO "drivers" VALUES ("22", "Sebastien", "Bourdais");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1", "1:34:50.616", "5690616", "1");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "2", "+5.478", "5696094", "1");
INSERT INTO "results" VALUES ("3", "1", "3", "3", "3", "+8.163", "5698779", "1");
INSERT INTO "results" VALUES ("4", "1", "4", "4", "4", "+17.181", "5707797", "1");
INSERT INTO "results" VALUES ("5", "1", "5", "6", "5", "+1 lap", "5750616", "1");
INSERT INTO "results" VALUES ("6", "1", "6", "7", "6", "+1 lap", "5760616", "1");
INSERT INTO "results" VALUES ("7", "1", "7", "8", "7", "+1 lap", "5770616", "1");
INSERT INTO "results" VALUES ("8", "1", "8", "9", "8", "+1 lap", "5780616", "1");
INSERT INTO "results" VALUES ("9", "1", "9", "10", "9", "+1 lap", "5790616", "1");
INSERT INTO "results" VALUES ("10", "1", "10", "11", "10", "+1 lap", "5800616", "1");
INSERT INTO "results" VALUES ("11", "1", "11", "12", "11", "+1 lap", "5810616", "1");
INSERT INTO "results" VALUES ("12", "1", "12", "13", "12", "+1 lap", "5820616", "1");
INSERT INTO "results" VALUES ("13", "1", "13", "14", "13", "+1 lap", "5830616", "1");
INSERT INTO "results" VALUES ("14", "1", "14", "15", "14", "+1 lap", "5840616", "1");
INSERT INTO "results" VALUES ("15", "1", "15", "16", "15", "+1 lap", "5850616", "1");
INSERT INTO "results" VALUES ("16", "1", "16", "17", "16", "+1 lap", "5860616", "1");
INSERT INTO "results" VALUES ("17", "1", "17", "18", "17", "+1 lap", "5870616", "1");
INSERT INTO "results" VALUES ("18", "1", "18", "19", "18", "+1 lap", "5880616", "1");
INSERT INTO "results" VALUES ("19", "1", "19", "20", "19", "+1 lap", "5890616", "1");
INSERT INTO "results" VALUES ("20", "1", "20", "21", "20", "+1 lap", "5900616", "1");
INSERT INTO "results" VALUES ("21", "1", "21", "22", "21", "+1 lap", "5910616", "1");
INSERT INTO "results" VALUES ("22", "1", "22", "5", "22", "+1 lap", "5920616", "1");
INSERT INTO "results" VALUES ("23", "2", "1", "1", "1", "1:31:18.555", "5478555", "1");
INSERT INTO "results" VALUES ("24", "2", "2", "2", "2", "+10.000", "5488555", "1");
INSERT INTO "circuits" VALUES ("1", "Albert Park Grand Prix Circuit");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit");
INSERT INTO "constructors" VALUES ("1", "McLaren");
INSERT INTO "constructors" VALUES ("2", "BMW Sauber");
INSERT INTO "constructors" VALUES ("3", "Williams");
INSERT INTO "constructors" VALUES ("4", "Renault");
INSERT INTO "constructors" VALUES ("5", "Honda");
INSERT INTO "constructors" VALUES ("6", "Ferrari");
INSERT INTO "constructors" VALUES ("7", "Force India");
INSERT INTO "constructors" VALUES ("8", "Toyota");
INSERT INTO "constructors" VALUES ("9", "Red Bull");
INSERT INTO "constructors" VALUES ("10", "Super Aguri");
INSERT INTO "constructors" VALUES ("11", "Toro Rosso");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "1:30.000");
INSERT INTO "lapTimes" VALUES ("1", "1", "2", "1:29.500");
INSERT INTO "lapTimes" VALUES ("1", "22", "1", "1:35.000");
INSERT INTO "lapTimes" VALUES ("1", "22", "2", "1:34.500");