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,
"year" INT,
"round" 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", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Massa");
INSERT INTO "drivers" VALUES ("3", "Raikkonen");
INSERT INTO "drivers" VALUES ("4", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Kubica");
INSERT INTO "drivers" VALUES ("6", "Button");
INSERT INTO "drivers" VALUES ("7", "Heidfeld");
INSERT INTO "drivers" VALUES ("8", "Barrichello");
INSERT INTO "drivers" VALUES ("9", "Kovalainen");
INSERT INTO "drivers" VALUES ("10", "Webber");
INSERT INTO "races" VALUES ("101", "2008", "1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2008", "2", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("103", "2008", "3", "Bahrain Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1:24:00.123");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "1:24:05.456");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "1:24:10.789");
INSERT INTO "results" VALUES ("1004", "101", "4", "4", "1:24:20.000");
INSERT INTO "results" VALUES ("1005", "101", "5", "5", "1:24:30.321");
INSERT INTO "results" VALUES ("1006", "101", "6", "6", "NULL");
INSERT INTO "results" VALUES ("1007", "101", "7", "7", "1:25:00.654");
INSERT INTO "results" VALUES ("1008", "101", "8", "8", "NULL");
INSERT INTO "results" VALUES ("1009", "101", "9", "9", "1:26:00.987");
INSERT INTO "results" VALUES ("1010", "101", "10", "10", "1:26:30.111");
INSERT INTO "results" VALUES ("1011", "102", "1", "2", "1:30:00.000");
INSERT INTO "results" VALUES ("1012", "102", "2", "1", "1:29:55.000");
INSERT INTO "results" VALUES ("1013", "102", "3", "3", "1:30:10.000");
INSERT INTO "results" VALUES ("1014", "103", "1", "1", "1:35:00.000");
INSERT INTO "results" VALUES ("1015", "103", "2", "2", "1:35:05.000");
INSERT INTO "results" VALUES ("1016", "103", "3", "3", "1:35:10.000");