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



INSERT INTO "drivers" VALUES ("1", "Schumacher");
INSERT INTO "drivers" VALUES ("2", "Alonso");
INSERT INTO "drivers" VALUES ("3", "Raikkonen");
INSERT INTO "drivers" VALUES ("4", "Button");
INSERT INTO "drivers" VALUES ("5", "Massa");
INSERT INTO "drivers" VALUES ("6", "Montoya");
INSERT INTO "drivers" VALUES ("7", "Heidfeld");
INSERT INTO "drivers" VALUES ("8", "Fisichella");
INSERT INTO "drivers" VALUES ("9", "Coulthard");
INSERT INTO "drivers" VALUES ("10", "Trulli");
INSERT INTO "drivers" VALUES ("11", "Barrichello");
INSERT INTO "drivers" VALUES ("12", "Webber");
INSERT INTO "races" VALUES ("101", "2006", "17", "United States Grand Prix");
INSERT INTO "races" VALUES ("102", "2006", "18", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("103", "2005", "17", "United States Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1", "1:12.345");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "2", "1:12.567");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "3", "1:12.789");
INSERT INTO "results" VALUES ("1004", "101", "4", "4", "4", "1:13.001");
INSERT INTO "results" VALUES ("1005", "101", "5", "5", "5", "1:13.123");
INSERT INTO "results" VALUES ("1006", "101", "6", "6", "6", "1:13.234");
INSERT INTO "results" VALUES ("1007", "101", "7", "7", "7", "1:13.345");
INSERT INTO "results" VALUES ("1008", "101", "8", "8", "8", "1:13.456");
INSERT INTO "results" VALUES ("1009", "101", "9", "9", "9", "1:13.567");
INSERT INTO "results" VALUES ("1010", "101", "10", "10", "10", "1:13.678");
INSERT INTO "results" VALUES ("1011", "101", "11", "11", "11", "1:14.000");
INSERT INTO "results" VALUES ("1012", "102", "1", "1", "1", "1:11.999");
INSERT INTO "results" VALUES ("1013", "103", "1", "1", "1", "1:12.111");