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

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"constructorId" INT,
"position" INT,
"fastestLapSpeed" 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", "Button");
INSERT INTO "drivers" VALUES ("3", "Vettel");
INSERT INTO "drivers" VALUES ("4", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Massa");
INSERT INTO "races" VALUES ("101", "2009", "Spanish Grand Prix", "2009-05-10");
INSERT INTO "races" VALUES ("102", "2009", "Monaco Grand Prix", "2009-05-24");
INSERT INTO "races" VALUES ("103", "2009", "British Grand Prix", "2009-07-19");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1", "190.5");
INSERT INTO "results" VALUES ("1002", "101", "2", "1", "2", "189.7");
INSERT INTO "results" VALUES ("1003", "101", "3", "2", "3", "191.2");
INSERT INTO "results" VALUES ("1004", "101", "4", "3", "4", "190.9");
INSERT INTO "results" VALUES ("1005", "101", "5", "3", "5", "188.3");
INSERT INTO "results" VALUES ("1006", "102", "1", "1", "2", "192.1");
INSERT INTO "results" VALUES ("1007", "102", "3", "2", "1", "193.0");
INSERT INTO "results" VALUES ("1008", "102", "4", "3", "3", "191.5");
INSERT INTO "results" VALUES ("1009", "103", "2", "1", "1", "189.9");
INSERT INTO "results" VALUES ("1010", "103", "5", "3", "2", "190.0");
INSERT INTO "results" VALUES ("1011", "103", "4", "3", "3", "189.5");