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", "Webber");
INSERT INTO "drivers" VALUES ("10", "Kovalainen");
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:19.123");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "1:24:20.456");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "1:24:22.789");
INSERT INTO "results" VALUES ("1004", "101", "4", "4", "1:24:30.000");
INSERT INTO "results" VALUES ("1005", "101", "5", "5", "1:24:45.321");
INSERT INTO "results" VALUES ("1006", "101", "6", "6", "1:25:00.654");
INSERT INTO "results" VALUES ("1007", "101", "7", "7", "1:25:15.987");
INSERT INTO "results" VALUES ("1008", "101", "8", "8", "1:25:30.210");
INSERT INTO "results" VALUES ("1009", "101", "9", "9", "NULL");
INSERT INTO "results" VALUES ("1010", "101", "10", "10", "NULL");
INSERT INTO "results" VALUES ("1011", "102", "1", "1", "1:30:00.000");
INSERT INTO "results" VALUES ("1012", "102", "2", "2", "1:30:10.000");
INSERT INTO "results" VALUES ("1013", "103", "3", "1", "1:28:00.000");