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,
"round" INT,
"name" TEXT,
PRIMARY KEY ("raceId")
);

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);



INSERT INTO "drivers" VALUES ("1", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("2", "Button", "British");
INSERT INTO "drivers" VALUES ("3", "Alonso", "Spanish");
INSERT INTO "drivers" VALUES ("4", "Raikkonen", "Finnish");
INSERT INTO "drivers" VALUES ("5", "Massa", "Brazilian");
INSERT INTO "drivers" VALUES ("6", "Webber", "Australian");
INSERT INTO "drivers" VALUES ("7", "Kubica", "Polish");
INSERT INTO "drivers" VALUES ("8", "Barrichello", "Brazilian");
INSERT INTO "drivers" VALUES ("9", "Heidfeld", "German");
INSERT INTO "drivers" VALUES ("10", "Sutil", "German");
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 "races" VALUES ("104", "2008", "4", "Spanish Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "1");
INSERT INTO "results" VALUES ("1002", "101", "2", "3");
INSERT INTO "results" VALUES ("1003", "101", "3", "2");
INSERT INTO "results" VALUES ("1004", "101", "4", "4");
INSERT INTO "results" VALUES ("1005", "101", "5", "5");
INSERT INTO "results" VALUES ("1006", "101", "6", "6");
INSERT INTO "results" VALUES ("1007", "101", "7", "7");
INSERT INTO "results" VALUES ("1008", "101", "8", "8");
INSERT INTO "results" VALUES ("1009", "101", "9", "9");
INSERT INTO "results" VALUES ("1010", "101", "10", "10");
INSERT INTO "results" VALUES ("1011", "102", "1", "2");
INSERT INTO "results" VALUES ("1012", "102", "2", "1");
INSERT INTO "results" VALUES ("1013", "102", "3", "3");
INSERT INTO "results" VALUES ("1014", "102", "4", "4");
INSERT INTO "results" VALUES ("1015", "102", "5", "5");