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 "constructors" (
"constructorId" INT UNIQUE,
"constructorRef" TEXT,
"url" TEXT,
PRIMARY KEY ("constructorId")
);

CREATE TABLE "drivers" (
"driverId" INT,
"forename" 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,
"constructorId" INT,
"position" INT,
"time" TEXT,
"milliseconds" INT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId"),
FOREIGN KEY ("constructorId") REFERENCES "constructors"("constructorId")
);



INSERT INTO "constructors" VALUES ("1", "brawngp", "http://en.wikipedia.org/wiki/Brawn_GP");
INSERT INTO "constructors" VALUES ("2", "red_bull", "http://en.wikipedia.org/wiki/Red_Bull_Racing");
INSERT INTO "constructors" VALUES ("3", "ferrari", "http://en.wikipedia.org/wiki/Ferrari");
INSERT INTO "constructors" VALUES ("4", "mclaren", "http://en.wikipedia.org/wiki/McLaren");
INSERT INTO "constructors" VALUES ("5", "mercedes", "http://en.wikipedia.org/wiki/Mercedes-Benz_in_Formula_One");
INSERT INTO "constructors" VALUES ("6", "williams", "http://en.wikipedia.org/wiki/Williams_Grand_Prix_Engineering");
INSERT INTO "drivers" VALUES ("1", "Jenson");
INSERT INTO "drivers" VALUES ("2", "Sebastian");
INSERT INTO "drivers" VALUES ("3", "Fernando");
INSERT INTO "drivers" VALUES ("4", "Lewis");
INSERT INTO "drivers" VALUES ("5", "Nico");
INSERT INTO "drivers" VALUES ("6", "Rubens");
INSERT INTO "races" VALUES ("1", "2009", "Singapore Grand Prix");
INSERT INTO "races" VALUES ("2", "2009", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("3", "2010", "Singapore Grand Prix");
INSERT INTO "races" VALUES ("4", "2008", "Singapore Grand Prix");
INSERT INTO "races" VALUES ("5", "2009", "Monaco Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1", "1:59:31.460", "7171460");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "2", "1:59:32.460", "7172460");
INSERT INTO "results" VALUES ("3", "1", "3", "3", "3", "1:59:33.460", "7173460");
INSERT INTO "results" VALUES ("4", "1", "4", "4", "4", "1:59:34.460", "7174460");
INSERT INTO "results" VALUES ("5", "2", "6", "1", "1", "1:30:00.000", "5400000");
INSERT INTO "results" VALUES ("6", "2", "1", "1", "5", "1:30:05.000", "5405000");
INSERT INTO "results" VALUES ("7", "3", "2", "2", "1", "1:59:00.000", "7140000");
INSERT INTO "results" VALUES ("8", "4", "3", "3", "1", "1:59:10.000", "7150000");
INSERT INTO "results" VALUES ("9", "5", "1", "1", "1", "1:40:00.000", "6000000");
INSERT INTO "results" VALUES ("10", "1", "6", "1", "10", "2:00:00.000", "7200000");