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,
"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,
"code" TEXT,
"forename" TEXT,
"surname" TEXT,
"dob" DATE,
"nationality" TEXT,
PRIMARY KEY ("driverId")
);

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

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



INSERT INTO "races" VALUES ("1", "2010");
INSERT INTO "races" VALUES ("2", "2011");
INSERT INTO "races" VALUES ("3", "2012");
INSERT INTO "races" VALUES ("4", "2013");
INSERT INTO "races" VALUES ("5", "2014");
INSERT INTO "drivers" VALUES ("101", "HAM", "Lewis", "Hamilton", "1985-01-07", "British");
INSERT INTO "drivers" VALUES ("102", "VET", "Sebastian", "Vettel", "1987-07-03", "German");
INSERT INTO "drivers" VALUES ("103", "ROS", "Nico", "Rosberg", "1985-06-27", "German");
INSERT INTO "drivers" VALUES ("104", "SCH", "Michael", "Schumacher", "1969-01-03", "German");
INSERT INTO "drivers" VALUES ("105", "HUL", "Nico", "Hülkenberg", "1987-08-19", "German");
INSERT INTO "drivers" VALUES ("106", "WEB", "Mark", "Webber", "1976-08-27", "Australian");
INSERT INTO "drivers" VALUES ("107", "BUT", "Jenson", "Button", "1980-01-19", "British");
INSERT INTO "drivers" VALUES ("108", "GUT", "Timo", "Glock", "1982-03-18", "German");
INSERT INTO "drivers" VALUES ("109", "BUE", "Adrian", "Sutil", "1983-01-11", "German");
INSERT INTO "drivers" VALUES ("110", "KOB", "Sebastian", "Kobayashi", "1983-05-23", "Japanese");
INSERT INTO "pitStops" VALUES ("1", "103", "1", "20.500");
INSERT INTO "pitStops" VALUES ("2", "103", "1", "19.800");
INSERT INTO "pitStops" VALUES ("3", "103", "1", "21.200");
INSERT INTO "pitStops" VALUES ("1", "108", "1", "22.000");
INSERT INTO "pitStops" VALUES ("2", "108", "1", "21.500");
INSERT INTO "pitStops" VALUES ("3", "108", "1", "22.300");
INSERT INTO "pitStops" VALUES ("1", "109", "1", "19.000");
INSERT INTO "pitStops" VALUES ("2", "109", "1", "18.500");
INSERT INTO "pitStops" VALUES ("3", "109", "1", "19.200");
INSERT INTO "pitStops" VALUES ("1", "102", "1", "18.000");
INSERT INTO "pitStops" VALUES ("2", "102", "1", "17.500");
INSERT INTO "pitStops" VALUES ("3", "102", "1", "18.200");
INSERT INTO "pitStops" VALUES ("1", "101", "1", "20.000");
INSERT INTO "pitStops" VALUES ("2", "101", "1", "19.500");
INSERT INTO "pitStops" VALUES ("3", "101", "1", "20.300");
INSERT INTO "pitStops" VALUES ("1", "107", "1", "21.000");
INSERT INTO "pitStops" VALUES ("2", "107", "1", "20.800");
INSERT INTO "pitStops" VALUES ("3", "107", "1", "21.200");