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

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

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



INSERT INTO "drivers" VALUES ("1", "alonso", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("2", "hamilton", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("3", "vettel", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("4", "paul_di_resta", "Paul", "di Resta");
INSERT INTO "drivers" VALUES ("5", "webber", "Mark", "Webber");
INSERT INTO "drivers" VALUES ("6", "rosberg", "Nico", "Rosberg");
INSERT INTO "races" VALUES ("853", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("854", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("855", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("856", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("857", "Monaco Grand Prix");
INSERT INTO "results" VALUES ("1", "853", "4", "1", "210.500");
INSERT INTO "results" VALUES ("2", "853", "1", "2", "209.800");
INSERT INTO "results" VALUES ("3", "853", "2", "3", "209.100");
INSERT INTO "results" VALUES ("4", "854", "4", "1", "205.000");
INSERT INTO "results" VALUES ("5", "854", "3", "4", "204.500");
INSERT INTO "results" VALUES ("6", "854", "5", "5", "203.900");
INSERT INTO "results" VALUES ("7", "855", "1", "2", "200.000");
INSERT INTO "results" VALUES ("8", "855", "2", "3", "199.500");
INSERT INTO "results" VALUES ("9", "856", "4", "1", "208.000");
INSERT INTO "results" VALUES ("10", "857", "6", "6", "207.500");