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

CREATE TABLE "pitStops" (
"raceId" INT,
"driverId" INT,
"stop" INT,
"duration" TEXT,
PRIMARY KEY ("raceId", "driverId", "stop")
);

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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"q3" TEXT,
PRIMARY KEY ("qualifyId")
);

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

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



INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("3", "Kimi", "Raikkonen");
INSERT INTO "drivers" VALUES ("4", "Felipe", "Massa");
INSERT INTO "drivers" VALUES ("5", "Sebastian", "Vettel");
INSERT INTO "races" VALUES ("101", "2008", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2008", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("103", "2009", "Australian Grand Prix");
INSERT INTO "races" VALUES ("104", "2008", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("105", "2007", "Australian Grand Prix");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "1:30.000", "90000");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "1:28.500", "88500");
INSERT INTO "lapTimes" VALUES ("101", "1", "3", "1:29.100", "89100");
INSERT INTO "lapTimes" VALUES ("101", "1", "4", "1:28.000", "88000");
INSERT INTO "lapTimes" VALUES ("101", "1", "5", "1:28.200", "88200");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "1:31.000", "91000");
INSERT INTO "lapTimes" VALUES ("101", "2", "2", "1:29.000", "89000");
INSERT INTO "lapTimes" VALUES ("102", "1", "1", "1:35.000", "95000");
INSERT INTO "lapTimes" VALUES ("103", "1", "1", "1:27.000", "87000");
INSERT INTO "lapTimes" VALUES ("101", "3", "1", "1:28.100", "88100");
INSERT INTO "results" VALUES ("1", "101", "1", "1", "4", "1:28.000", "215.000");
INSERT INTO "results" VALUES ("2", "101", "2", "2", "2", "1:29.000", "213.000");
INSERT INTO "results" VALUES ("3", "102", "1", "5", "10", "1:35.000", "200.000");
INSERT INTO "results" VALUES ("4", "103", "1", "3", "5", "1:27.000", "218.000");
INSERT INTO "results" VALUES ("5", "101", "3", "3", "1", "1:28.100", "214.500");
INSERT INTO "pitStops" VALUES ("101", "1", "1", "25.000");
INSERT INTO "pitStops" VALUES ("101", "2", "1", "26.000");
INSERT INTO "qualifying" VALUES ("1", "1:26.000");
INSERT INTO "qualifying" VALUES ("2", "1:27.000");