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

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

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



INSERT INTO "drivers" VALUES ("44", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("1", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("2", "Jenson", "Button", "British");
INSERT INTO "drivers" VALUES ("3", "Mark", "Webber", "Australian");
INSERT INTO "drivers" VALUES ("5", "Fernando", "Alonso", "Spanish");
INSERT INTO "races" VALUES ("101", "2011", "Australian Grand Prix", "2011-03-27");
INSERT INTO "races" VALUES ("102", "2011", "Malaysian Grand Prix", "2011-04-10");
INSERT INTO "races" VALUES ("103", "2012", "Australian Grand Prix", "2012-03-18");
INSERT INTO "pitStops" VALUES ("101", "44", "1", "15", "14:32:10", "2.5");
INSERT INTO "pitStops" VALUES ("101", "44", "2", "38", "14:55:45", "2.7");
INSERT INTO "pitStops" VALUES ("101", "1", "1", "12", "14:29:50", "2.3");
INSERT INTO "pitStops" VALUES ("101", "2", "1", "20", "14:37:30", "2.6");
INSERT INTO "pitStops" VALUES ("101", "3", "1", "18", "14:35:10", "2.4");
INSERT INTO "pitStops" VALUES ("101", "5", "1", "22", "14:39:00", "2.8");
INSERT INTO "pitStops" VALUES ("102", "44", "1", "14", "15:10:05", "2.4");
INSERT INTO "pitStops" VALUES ("102", "44", "2", "37", "15:33:20", "2.6");
INSERT INTO "pitStops" VALUES ("102", "1", "1", "13", "15:08:30", "2.5");
INSERT INTO "pitStops" VALUES ("102", "2", "1", "21", "15:16:40", "2.7");
INSERT INTO "pitStops" VALUES ("102", "3", "1", "19", "15:14:10", "2.3");
INSERT INTO "pitStops" VALUES ("102", "5", "1", "23", "15:18:00", "2.9");