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,
"forename" TEXT,
"surname" TEXT,
"nationality" TEXT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"name" TEXT,
PRIMARY KEY ("raceId")
);

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



INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("2", "Kimi", "Raikkonen", "Finnish");
INSERT INTO "drivers" VALUES ("3", "Felipe", "Massa", "Brazilian");
INSERT INTO "drivers" VALUES ("4", "Robert", "Kubica", "Polish");
INSERT INTO "drivers" VALUES ("5", "Fernando", "Alonso", "Spanish");
INSERT INTO "races" VALUES ("101", "2008", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("102", "2008", "Australian Grand Prix");
INSERT INTO "races" VALUES ("103", "2008", "Monaco Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "33", "3", "3");
INSERT INTO "results" VALUES ("1002", "101", "2", "7", "1", "1");
INSERT INTO "results" VALUES ("1003", "101", "3", "2", "2", "2");
INSERT INTO "results" VALUES ("1004", "101", "4", "11", "5", "5");
INSERT INTO "results" VALUES ("1005", "101", "5", "12", "4", "4");
INSERT INTO "results" VALUES ("1006", "102", "1", "33", "1", "1");
INSERT INTO "results" VALUES ("1007", "102", "2", "7", "2", "2");
INSERT INTO "results" VALUES ("1008", "102", "3", "2", "3", "3");
INSERT INTO "results" VALUES ("1009", "103", "1", "33", "2", "2");
INSERT INTO "results" VALUES ("1010", "103", "5", "12", "1", "1");
INSERT INTO "results" VALUES ("1011", "103", "4", "11", "3", "3");