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

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



INSERT INTO "drivers" VALUES ("1", "Prost");
INSERT INTO "drivers" VALUES ("2", "Senna");
INSERT INTO "drivers" VALUES ("3", "Piquet");
INSERT INTO "drivers" VALUES ("4", "Lauda");
INSERT INTO "drivers" VALUES ("5", "Alboreto");
INSERT INTO "drivers" VALUES ("6", "Rosberg");
INSERT INTO "races" VALUES ("101", "British Grand Prix", "1983-07-16");
INSERT INTO "races" VALUES ("102", "German Grand Prix", "1983-08-07");
INSERT INTO "races" VALUES ("103", "Italian Grand Prix", "1983-09-04");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Accident");
INSERT INTO "status" VALUES ("3", "Engine");
INSERT INTO "status" VALUES ("4", "Disqualified");
INSERT INTO "results" VALUES ("1001", "101", "1", "1:30:15.123");
INSERT INTO "results" VALUES ("1002", "101", "2", "1:31:02.456");
INSERT INTO "results" VALUES ("1003", "101", "3", "NULL");
INSERT INTO "results" VALUES ("1004", "101", "4", "1:32:10.789");
INSERT INTO "results" VALUES ("1005", "101", "5", "NULL");
INSERT INTO "results" VALUES ("1006", "101", "6", "1:33:05.234");
INSERT INTO "results" VALUES ("1007", "102", "1", "1:28:45.000");
INSERT INTO "results" VALUES ("1008", "102", "3", "1:29:10.500");
INSERT INTO "results" VALUES ("1009", "102", "5", "1:30:00.000");
INSERT INTO "results" VALUES ("1010", "103", "2", "1:27:30.000");
INSERT INTO "results" VALUES ("1011", "103", "4", "NULL");
INSERT INTO "results" VALUES ("1012", "103", "6", "1:28:15.000");