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



INSERT INTO "drivers" VALUES ("1", "Tanaka", "Japanese");
INSERT INTO "drivers" VALUES ("2", "Sato", "Japanese");
INSERT INTO "drivers" VALUES ("3", "Kobayashi", "Japanese");
INSERT INTO "drivers" VALUES ("4", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("5", "Vettel", "German");
INSERT INTO "drivers" VALUES ("6", "Alonso", "Spanish");
INSERT INTO "races" VALUES ("101", "2007", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2007", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("103", "2008", "British Grand Prix");
INSERT INTO "races" VALUES ("104", "2008", "Belgian Grand Prix");
INSERT INTO "races" VALUES ("105", "2009", "Italian Grand Prix");
INSERT INTO "races" VALUES ("106", "2009", "Singapore Grand Prix");
INSERT INTO "races" VALUES ("107", "2010", "Japanese Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "5", "1:32:15");
INSERT INTO "results" VALUES ("1002", "101", "2", "12", "NULL");
INSERT INTO "results" VALUES ("1003", "101", "3", "8", "1:33:05");
INSERT INTO "results" VALUES ("1004", "101", "4", "1", "1:30:45");
INSERT INTO "results" VALUES ("1005", "101", "5", "3", "1:31:10");
INSERT INTO "results" VALUES ("1006", "101", "6", "7", "1:32:50");
INSERT INTO "results" VALUES ("1007", "102", "1", "10", "NULL");
INSERT INTO "results" VALUES ("1008", "102", "2", "6", "1:35:20");
INSERT INTO "results" VALUES ("1009", "102", "3", "15", "NULL");
INSERT INTO "results" VALUES ("1010", "102", "4", "2", "1:33:00");
INSERT INTO "results" VALUES ("1011", "102", "5", "4", "1:33:30");
INSERT INTO "results" VALUES ("1012", "102", "6", "9", "1:34:10");
INSERT INTO "results" VALUES ("1013", "103", "1", "7", "1:28:40");
INSERT INTO "results" VALUES ("1014", "103", "2", "14", "NULL");
INSERT INTO "results" VALUES ("1015", "103", "3", "11", "1:29:15");
INSERT INTO "results" VALUES ("1016", "103", "4", "1", "1:27:50");
INSERT INTO "results" VALUES ("1017", "103", "5", "5", "1:28:10");
INSERT INTO "results" VALUES ("1018", "103", "6", "8", "1:29:00");
INSERT INTO "results" VALUES ("1019", "104", "1", "9", "1:40:05");
INSERT INTO "results" VALUES ("1020", "104", "2", "13", "NULL");
INSERT INTO "results" VALUES ("1021", "104", "3", "10", "1:39:50");
INSERT INTO "results" VALUES ("1022", "104", "4", "3", "1:38:30");
INSERT INTO "results" VALUES ("1023", "104", "5", "6", "1:39:00");
INSERT INTO "results" VALUES ("1024", "104", "6", "12", "NULL");
INSERT INTO "results" VALUES ("1025", "105", "1", "4", "1:25:30");
INSERT INTO "results" VALUES ("1026", "105", "2", "7", "1:26:10");
INSERT INTO "results" VALUES ("1027", "105", "3", "13", "NULL");
INSERT INTO "results" VALUES ("1028", "105", "4", "2", "1:24:50");
INSERT INTO "results" VALUES ("1029", "105", "5", "1", "1:24:30");
INSERT INTO "results" VALUES ("1030", "105", "6", "5", "1:25:00");
INSERT INTO "results" VALUES ("1031", "106", "1", "6", "1:31:45");
INSERT INTO "results" VALUES ("1032", "106", "2", "11", "NULL");
INSERT INTO "results" VALUES ("1033", "106", "3", "14", "NULL");
INSERT INTO "results" VALUES ("1034", "106", "4", "3", "1:30:10");
INSERT INTO "results" VALUES ("1035", "106", "5", "7", "1:30:50");
INSERT INTO "results" VALUES ("1036", "106", "6", "9", "1:31:20");
INSERT INTO "results" VALUES ("1037", "107", "1", "8", "1:29:40");
INSERT INTO "results" VALUES ("1038", "107", "2", "10", "1:30:05");
INSERT INTO "results" VALUES ("1039", "107", "3", "12", "NULL");
INSERT INTO "results" VALUES ("1040", "107", "4", "1", "1:28:00");
INSERT INTO "results" VALUES ("1041", "107", "5", "4", "1:28:30");
INSERT INTO "results" VALUES ("1042", "107", "6", "6", "1:29:00");