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,
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", "Alonso");
INSERT INTO "drivers" VALUES ("3", "Massa");
INSERT INTO "drivers" VALUES ("4", "Raikkonen");
INSERT INTO "drivers" VALUES ("5", "Button");
INSERT INTO "drivers" VALUES ("6", "Kubica");
INSERT INTO "drivers" VALUES ("7", "Heidfeld");
INSERT INTO "drivers" VALUES ("8", "Webber");
INSERT INTO "drivers" VALUES ("9", "Barrichello");
INSERT INTO "drivers" VALUES ("10", "Trulli");
INSERT INTO "races" VALUES ("101", "2007", "1", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("102", "2007", "2", "Australian Grand Prix");
INSERT INTO "races" VALUES ("103", "2007", "3", "Malaysian Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1:32:45.123");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "1:32:47.456");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "1:32:50.789");
INSERT INTO "results" VALUES ("1004", "101", "4", "4", "1:33:10.234");
INSERT INTO "results" VALUES ("1005", "101", "5", "5", "1:33:20.567");
INSERT INTO "results" VALUES ("1006", "101", "6", "6", "");
INSERT INTO "results" VALUES ("1007", "101", "7", "7", "NULL");
INSERT INTO "results" VALUES ("1008", "101", "8", "8", "1:34:00.890");
INSERT INTO "results" VALUES ("1009", "101", "9", "9", "NULL");
INSERT INTO "results" VALUES ("1010", "101", "10", "10", "1:34:10.123");
INSERT INTO "results" VALUES ("1011", "102", "1", "1", "1:30:00.000");
INSERT INTO "results" VALUES ("1012", "102", "2", "2", "1:30:05.000");
INSERT INTO "results" VALUES ("1013", "103", "3", "1", "1:31:00.000");