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



INSERT INTO "races" VALUES ("101", "2011", "1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2011", "2", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("103", "2012", "1", "Australian Grand Prix");
INSERT INTO "drivers" VALUES ("201", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("202", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("203", "Jenson", "Button", "British");
INSERT INTO "drivers" VALUES ("204", "Mark", "Webber", "Australian");
INSERT INTO "drivers" VALUES ("205", "Fernando", "Alonso", "Spanish");
INSERT INTO "pitStops" VALUES ("101", "201", "1", "15", "14:32:10", "22.345");
INSERT INTO "pitStops" VALUES ("101", "201", "2", "40", "14:55:30", "21.789");
INSERT INTO "pitStops" VALUES ("101", "202", "1", "18", "14:35:20", "23.001");
INSERT INTO "pitStops" VALUES ("101", "202", "2", "42", "14:57:50", "22.500");
INSERT INTO "pitStops" VALUES ("101", "203", "1", "16", "14:33:00", "24.100");
INSERT INTO "pitStops" VALUES ("101", "204", "1", "17", "14:34:10", "21.900");
INSERT INTO "pitStops" VALUES ("101", "205", "1", "19", "14:36:00", "23.450");
INSERT INTO "pitStops" VALUES ("102", "201", "1", "14", "15:10:00", "20.500");
INSERT INTO "pitStops" VALUES ("103", "202", "1", "15", "14:30:00", "22.000");