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

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")
);

CREATE TABLE "results" (
"resultId" INT,
"position" INT,
PRIMARY KEY ("resultId")
);

CREATE TABLE "status" (
"statusId" INT,
"status" TEXT,
PRIMARY KEY ("statusId")
);



INSERT INTO "constructors" VALUES ("1", "McLaren");
INSERT INTO "constructors" VALUES ("2", "Ferrari");
INSERT INTO "constructors" VALUES ("3", "Mercedes");
INSERT INTO "drivers" VALUES ("44", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("5", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("7", "Kimi", "Raikkonen");
INSERT INTO "races" VALUES ("101", "2009", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("102", "2009", "Australian Grand Prix");
INSERT INTO "races" VALUES ("103", "2010", "Malaysian Grand Prix");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Retired");
INSERT INTO "status" VALUES ("3", "Disqualified");
INSERT INTO "lapTimes" VALUES ("101", "44", "1", "90000");
INSERT INTO "lapTimes" VALUES ("101", "44", "2", "89500");
INSERT INTO "lapTimes" VALUES ("101", "44", "3", "90200");
INSERT INTO "lapTimes" VALUES ("101", "44", "4", "89800");
INSERT INTO "lapTimes" VALUES ("101", "44", "5", "89900");
INSERT INTO "lapTimes" VALUES ("101", "5", "1", "91000");
INSERT INTO "lapTimes" VALUES ("101", "5", "2", "91200");
INSERT INTO "lapTimes" VALUES ("101", "7", "1", "92000");
INSERT INTO "lapTimes" VALUES ("101", "7", "2", "91800");
INSERT INTO "lapTimes" VALUES ("102", "44", "1", "88000");
INSERT INTO "lapTimes" VALUES ("102", "44", "2", "88200");
INSERT INTO "lapTimes" VALUES ("103", "44", "1", "87000");
INSERT INTO "lapTimes" VALUES ("103", "44", "2", "87500");