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,
"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,
"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 "drivers" VALUES ("1", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Alonso");
INSERT INTO "drivers" VALUES ("4", "Raikkonen");
INSERT INTO "drivers" VALUES ("5", "Verstappen");
INSERT INTO "drivers" VALUES ("6", "Bottas");
INSERT INTO "races" VALUES ("101", "Abu Dhabi GP", "2015-11-29");
INSERT INTO "races" VALUES ("102", "Brazil GP", "2015-11-15");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Did Not Finish");
INSERT INTO "status" VALUES ("3", "Disqualified");
INSERT INTO "status" VALUES ("4", "Retired");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1:34:05.123", "1");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "1:34:10.456", "1");
INSERT INTO "results" VALUES ("1003", "101", "3", "NULL", "1:15:30.789", "2");
INSERT INTO "results" VALUES ("1004", "101", "4", "NULL", "1:20:45.321", "4");
INSERT INTO "results" VALUES ("1005", "101", "5", "3", "1:34:20.654", "1");
INSERT INTO "results" VALUES ("1006", "101", "6", "NULL", "1:10:00.000", "2");
INSERT INTO "results" VALUES ("1007", "102", "1", "1", "1:30:00.000", "1");
INSERT INTO "results" VALUES ("1008", "102", "2", "3", "1:30:10.000", "1");
INSERT INTO "results" VALUES ("1009", "102", "3", "2", "1:30:05.000", "1");
INSERT INTO "results" VALUES ("1010", "102", "4", "NULL", "NULL", "3");