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 "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"milliseconds" INT,
PRIMARY KEY ("raceId", "driverId", "lap"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"surname" TEXT,
PRIMARY KEY ("driverId")
);

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



INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("4", "Jenson", "Button");
INSERT INTO "drivers" VALUES ("5", "Kimi", "Raikkonen");
INSERT INTO "drivers" VALUES ("6", "Felipe", "Massa");
INSERT INTO "races" VALUES ("1", "2009", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("2", "2009", "Australian Grand Prix");
INSERT INTO "races" VALUES ("3", "2010", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("4", "2009", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("5", "2008", "Malaysian Grand Prix");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "95000");
INSERT INTO "lapTimes" VALUES ("1", "1", "2", "94500");
INSERT INTO "lapTimes" VALUES ("1", "1", "3", "95200");
INSERT INTO "lapTimes" VALUES ("1", "1", "4", "94800");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "96000");
INSERT INTO "lapTimes" VALUES ("1", "2", "2", "95500");
INSERT INTO "lapTimes" VALUES ("2", "1", "1", "98000");
INSERT INTO "lapTimes" VALUES ("3", "1", "1", "93000");
INSERT INTO "lapTimes" VALUES ("1", "1", "5", "94900");
INSERT INTO "lapTimes" VALUES ("1", "1", "6", "95100");
INSERT INTO "lapTimes" VALUES ("1", "1", "7", "94700");
INSERT INTO "lapTimes" VALUES ("1", "1", "8", "95300");
INSERT INTO "lapTimes" VALUES ("1", "1", "9", "94600");
INSERT INTO "lapTimes" VALUES ("1", "1", "10", "95050");
INSERT INTO "lapTimes" VALUES ("1", "4", "1", "97000");
INSERT INTO "lapTimes" VALUES ("1", "4", "2", "96500");
INSERT INTO "lapTimes" VALUES ("1", "1", "11", "94950");
INSERT INTO "lapTimes" VALUES ("1", "1", "12", "95150");
INSERT INTO "lapTimes" VALUES ("1", "1", "13", "94850");
INSERT INTO "lapTimes" VALUES ("1", "1", "14", "95250");
INSERT INTO "lapTimes" VALUES ("1", "1", "15", "94750");