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,
"nationality" 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,
"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 "drivers" VALUES ("1", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("2", "Nico", "Rosberg", "German");
INSERT INTO "drivers" VALUES ("3", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("4", "Kimi", "Raikkonen", "Finnish");
INSERT INTO "drivers" VALUES ("5", "Daniel", "Ricciardo", "Australian");
INSERT INTO "drivers" VALUES ("6", "Max", "Verstappen", "Dutch");
INSERT INTO "drivers" VALUES ("7", "Fernando", "Alonso", "Spanish");
INSERT INTO "drivers" VALUES ("8", "Jenson", "Button", "British");
INSERT INTO "drivers" VALUES ("9", "Felipe", "Massa", "Brazilian");
INSERT INTO "drivers" VALUES ("10", "Valtteri", "Bottas", "Finnish");
INSERT INTO "races" VALUES ("1", "Abu Dhabi Grand Prix", "2015-11-29");
INSERT INTO "races" VALUES ("2", "Brazilian Grand Prix", "2015-11-15");
INSERT INTO "races" VALUES ("3", "Japanese Grand Prix", "2015-09-27");
INSERT INTO "races" VALUES ("4", "Monaco Grand Prix", "2015-05-24");
INSERT INTO "races" VALUES ("5", "British Grand Prix", "2016-07-10");
INSERT INTO "races" VALUES ("6", "Italian Grand Prix", "2015-09-06");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Engine");
INSERT INTO "status" VALUES ("3", "Gearbox");
INSERT INTO "status" VALUES ("4", "Accident");
INSERT INTO "status" VALUES ("5", "Collision");
INSERT INTO "status" VALUES ("6", "Retired");
INSERT INTO "status" VALUES ("7", "Suspension");
INSERT INTO "status" VALUES ("8", "Brakes");
INSERT INTO "status" VALUES ("9", "Hydraulics");
INSERT INTO "status" VALUES ("10", "Puncture");
INSERT INTO "results" VALUES ("1", "1", "1", "1:38:51.000", "5931000", "1");
INSERT INTO "results" VALUES ("2", "1", "2", "1:38:59.000", "5939000", "1");
INSERT INTO "results" VALUES ("3", "1", "3", "1:39:05.000", "5945000", "1");
INSERT INTO "results" VALUES ("4", "1", "4", "NULL", "NULL", "2");
INSERT INTO "results" VALUES ("5", "1", "5", "NULL", "NULL", "3");
INSERT INTO "results" VALUES ("6", "1", "6", "NULL", "NULL", "4");
INSERT INTO "results" VALUES ("7", "1", "7", "NULL", "NULL", "6");
INSERT INTO "results" VALUES ("8", "2", "1", "1:31:00.000", "5460000", "1");
INSERT INTO "results" VALUES ("9", "2", "2", "1:31:05.000", "5465000", "1");
INSERT INTO "results" VALUES ("10", "2", "3", "NULL", "NULL", "2");
INSERT INTO "results" VALUES ("11", "3", "1", "1:28:00.000", "5280000", "1");
INSERT INTO "results" VALUES ("12", "3", "2", "1:28:02.000", "5282000", "1");
INSERT INTO "results" VALUES ("13", "3", "3", "1:28:05.000", "5285000", "1");
INSERT INTO "results" VALUES ("14", "4", "7", "NULL", "NULL", "4");
INSERT INTO "results" VALUES ("15", "4", "8", "NULL", "NULL", "5");
INSERT INTO "results" VALUES ("16", "5", "1", "1:20:00.000", "4800000", "1");
INSERT INTO "results" VALUES ("17", "5", "2", "NULL", "NULL", "2");
INSERT INTO "results" VALUES ("18", "6", "9", "1:18:00.000", "4680000", "1");
INSERT INTO "results" VALUES ("19", "6", "10", "NULL", "NULL", "6");
INSERT INTO "results" VALUES ("20", "1", "8", "1:40:00.000", "6000000", "1");
INSERT INTO "results" VALUES ("21", "1", "9", "NULL", "NULL", "7");
INSERT INTO "results" VALUES ("22", "1", "10", "NULL", "NULL", "8");