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

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

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



INSERT INTO "drivers" VALUES ("1", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Rosberg");
INSERT INTO "drivers" VALUES ("4", "Ricciardo");
INSERT INTO "drivers" VALUES ("5", "Alonso");
INSERT INTO "drivers" VALUES ("6", "Massa");
INSERT INTO "drivers" VALUES ("7", "Button");
INSERT INTO "drivers" VALUES ("8", "Hulkenberg");
INSERT INTO "races" VALUES ("101", "Abu Dhabi Grand Prix", "2015-11-29");
INSERT INTO "races" VALUES ("102", "Brazilian Grand Prix", "2015-11-15");
INSERT INTO "races" VALUES ("103", "Monaco Grand Prix", "2015-05-24");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1:34:05.715");
INSERT INTO "results" VALUES ("1002", "101", "3", "2", "1:34:07.123");
INSERT INTO "results" VALUES ("1003", "101", "2", "3", "1:34:10.456");
INSERT INTO "results" VALUES ("1004", "101", "4", "4", "1:34:20.789");
INSERT INTO "results" VALUES ("1005", "101", "5", "5", "1:34:30.012");
INSERT INTO "results" VALUES ("1006", "101", "6", "6", "1:34:45.678");
INSERT INTO "results" VALUES ("1007", "101", "7", "7", "1:35:00.234");
INSERT INTO "results" VALUES ("1008", "101", "8", "8", "NULL");
INSERT INTO "results" VALUES ("2001", "102", "1", "2", "1:30:00.000");
INSERT INTO "results" VALUES ("2002", "102", "2", "1", "1:29:55.000");
INSERT INTO "results" VALUES ("2003", "102", "3", "3", "1:30:10.000");
INSERT INTO "results" VALUES ("3001", "103", "4", "1", "1:40:00.000");
INSERT INTO "results" VALUES ("3002", "103", "5", "2", "1:40:05.000");
INSERT INTO "results" VALUES ("3003", "103", "6", "3", "1:40:10.000");