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 ("driverId") REFERENCES "drivers"("driverId")
);

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

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



INSERT INTO "drivers" VALUES ("1", "Carlos", "Sainz", "1969-09-01", "Spanish");
INSERT INTO "drivers" VALUES ("2", "Fernando", "Alonso", "1981-07-29", "Spanish");
INSERT INTO "drivers" VALUES ("3", "Pedro", "de la Rosa", "1971-02-24", "Spanish");
INSERT INTO "drivers" VALUES ("4", "Marc", "Gené", "1974-03-29", "Spanish");
INSERT INTO "drivers" VALUES ("5", "Jaime", "Alguersuari", "1990-03-23", "Spanish");
INSERT INTO "drivers" VALUES ("6", "Dani", "Juncadella", "1991-02-07", "Spanish");
INSERT INTO "drivers" VALUES ("7", "Roberto", "Merhi", "1991-03-22", "Spanish");
INSERT INTO "drivers" VALUES ("8", "Adrián", "Campos", "1960-06-17", "Spanish");
INSERT INTO "drivers" VALUES ("9", "Luis", "Pérez-Sala", "1959-11-15", "Spanish");
INSERT INTO "drivers" VALUES ("10", "Alfonso", "de Portago", "1928-11-11", "Spanish");
INSERT INTO "drivers" VALUES ("11", "Jorge", "Martínez", "1983-05-10", "Spanish");
INSERT INTO "drivers" VALUES ("12", "Esteban", "Gutiérrez", "1991-08-05", "Mexican");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "1:20.500", "80500");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "1:19.800", "79800");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "1:21.000", "81000");
INSERT INTO "lapTimes" VALUES ("101", "3", "1", "1:22.300", "82300");
INSERT INTO "lapTimes" VALUES ("101", "4", "1", "1:20.000", "80000");
INSERT INTO "lapTimes" VALUES ("101", "8", "1", "1:23.000", "83000");
INSERT INTO "lapTimes" VALUES ("101", "9", "1", "1:19.900", "79900");
INSERT INTO "lapTimes" VALUES ("101", "10", "1", "1:25.000", "85000");
INSERT INTO "lapTimes" VALUES ("102", "1", "1", "1:18.500", "78500");
INSERT INTO "lapTimes" VALUES ("102", "3", "1", "1:19.000", "79000");
INSERT INTO "lapTimes" VALUES ("102", "4", "1", "1:18.700", "78700");
INSERT INTO "lapTimes" VALUES ("102", "8", "1", "1:21.000", "81000");
INSERT INTO "lapTimes" VALUES ("102", "9", "1", "1:20.500", "80500");
INSERT INTO "lapTimes" VALUES ("102", "10", "1", "1:22.000", "82000");
INSERT INTO "lapTimes" VALUES ("101", "5", "1", "1:19.500", "79500");
INSERT INTO "lapTimes" VALUES ("101", "6", "1", "1:20.000", "80000");
INSERT INTO "lapTimes" VALUES ("101", "7", "1", "1:21.500", "81500");
INSERT INTO "lapTimes" VALUES ("101", "12", "1", "1:18.000", "78000");
INSERT INTO "results" VALUES ("201", "1", "78000", "1");
INSERT INTO "results" VALUES ("202", "2", "78500", "2");
INSERT INTO "results" VALUES ("203", "3", "79000", "3");
INSERT INTO "results" VALUES ("204", "4", "79500", "4");
INSERT INTO "results" VALUES ("205", "5", "80000", "5");
INSERT INTO "results" VALUES ("206", "6", "80500", "6");
INSERT INTO "results" VALUES ("207", "7", "81000", "7");
INSERT INTO "results" VALUES ("208", "8", "81500", "8");
INSERT INTO "results" VALUES ("209", "9", "82000", "9");
INSERT INTO "results" VALUES ("210", "10", "82500", "10");