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

CREATE TABLE "circuits" (
"circuitId" INT,
"name" TEXT,
PRIMARY KEY ("circuitId")
);

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

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

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

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



INSERT INTO "circuits" VALUES ("1", "Circuit de Barcelona-Catalunya");
INSERT INTO "circuits" VALUES ("2", "Monza");
INSERT INTO "circuits" VALUES ("3", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("4", "Spa-Francorchamps");
INSERT INTO "circuits" VALUES ("5", "Circuit de Monaco");
INSERT INTO "drivers" VALUES ("1", "Fernando", "Alonso", "1981-07-29", "Spanish");
INSERT INTO "drivers" VALUES ("2", "Carlos", "Sainz", "1994-09-01", "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-04-02", "Spanish");
INSERT INTO "drivers" VALUES ("6", "Roberto", "Merhi", "1991-03-27", "Spanish");
INSERT INTO "drivers" VALUES ("7", "Lewis", "Hamilton", "1985-01-07", "British");
INSERT INTO "drivers" VALUES ("8", "Max", "Verstappen", "1997-09-30", "Dutch");
INSERT INTO "drivers" VALUES ("9", "Michael", "Schumacher", "1969-01-03", "German");
INSERT INTO "drivers" VALUES ("10", "Juan Pablo", "Montoya", "1975-09-20", "Colombian");
INSERT INTO "drivers" VALUES ("11", "Rubens", "Barrichello", "1972-05-29", "Brazilian");
INSERT INTO "drivers" VALUES ("12", "Kimi", "Räikkönen", "1979-10-17", "Finnish");
INSERT INTO "drivers" VALUES ("13", "Jenson", "Button", "1980-01-19", "British");
INSERT INTO "drivers" VALUES ("14", "Felipe", "Massa", "1981-04-25", "Brazilian");
INSERT INTO "drivers" VALUES ("15", "Sebastian", "Vettel", "1987-07-03", "German");
INSERT INTO "races" VALUES ("1", "2005");
INSERT INTO "races" VALUES ("2", "2006");
INSERT INTO "races" VALUES ("3", "2007");
INSERT INTO "races" VALUES ("4", "2008");
INSERT INTO "races" VALUES ("5", "2009");
INSERT INTO "races" VALUES ("6", "2010");
INSERT INTO "races" VALUES ("7", "2011");
INSERT INTO "races" VALUES ("8", "2012");
INSERT INTO "races" VALUES ("9", "2013");
INSERT INTO "races" VALUES ("10", "2014");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "00:01:25.000");
INSERT INTO "lapTimes" VALUES ("1", "1", "2", "00:01:26.123");
INSERT INTO "lapTimes" VALUES ("1", "3", "1", "00:01:27.500");
INSERT INTO "lapTimes" VALUES ("1", "3", "2", "00:01:28.000");
INSERT INTO "lapTimes" VALUES ("2", "1", "1", "00:01:24.500");
INSERT INTO "lapTimes" VALUES ("2", "1", "2", "00:01:25.999");
INSERT INTO "lapTimes" VALUES ("2", "3", "1", "00:01:26.000");
INSERT INTO "lapTimes" VALUES ("2", "3", "2", "00:01:27.100");
INSERT INTO "lapTimes" VALUES ("3", "1", "1", "00:01:23.000");
INSERT INTO "lapTimes" VALUES ("3", "1", "2", "00:01:24.000");
INSERT INTO "lapTimes" VALUES ("3", "3", "1", "00:01:25.000");
INSERT INTO "lapTimes" VALUES ("3", "3", "2", "00:01:26.000");
INSERT INTO "lapTimes" VALUES ("4", "1", "1", "00:01:22.000");
INSERT INTO "lapTimes" VALUES ("4", "1", "2", "00:01:23.000");
INSERT INTO "lapTimes" VALUES ("4", "3", "1", "00:01:24.000");
INSERT INTO "lapTimes" VALUES ("4", "3", "2", "00:01:25.000");
INSERT INTO "lapTimes" VALUES ("5", "1", "1", "00:01:21.000");
INSERT INTO "lapTimes" VALUES ("5", "1", "2", "00:01:22.000");
INSERT INTO "lapTimes" VALUES ("5", "3", "1", "00:01:23.000");
INSERT INTO "lapTimes" VALUES ("5", "3", "2", "00:01:24.000");
INSERT INTO "lapTimes" VALUES ("6", "1", "1", "00:01:20.000");
INSERT INTO "lapTimes" VALUES ("6", "1", "2", "00:01:21.000");
INSERT INTO "lapTimes" VALUES ("6", "3", "1", "00:01:22.000");
INSERT INTO "lapTimes" VALUES ("6", "3", "2", "00:01:23.000");
INSERT INTO "lapTimes" VALUES ("7", "1", "1", "00:01:19.000");
INSERT INTO "lapTimes" VALUES ("7", "1", "2", "00:01:20.000");
INSERT INTO "lapTimes" VALUES ("7", "3", "1", "00:01:21.000");
INSERT INTO "lapTimes" VALUES ("7", "3", "2", "00:01:22.000");
INSERT INTO "lapTimes" VALUES ("8", "1", "1", "00:01:18.000");
INSERT INTO "lapTimes" VALUES ("8", "1", "2", "00:01:19.000");
INSERT INTO "lapTimes" VALUES ("8", "3", "1", "00:01:20.000");
INSERT INTO "lapTimes" VALUES ("8", "3", "2", "00:01:21.000");
INSERT INTO "lapTimes" VALUES ("9", "1", "1", "00:01:17.000");
INSERT INTO "lapTimes" VALUES ("9", "1", "2", "00:01:18.000");
INSERT INTO "lapTimes" VALUES ("9", "3", "1", "00:01:19.000");
INSERT INTO "lapTimes" VALUES ("9", "3", "2", "00:01:20.000");
INSERT INTO "lapTimes" VALUES ("10", "1", "1", "00:01:16.000");
INSERT INTO "lapTimes" VALUES ("10", "1", "2", "00:01:17.000");
INSERT INTO "lapTimes" VALUES ("10", "3", "1", "00:01:18.000");
INSERT INTO "lapTimes" VALUES ("10", "3", "2", "00:01:19.000");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "00:01:20.000");
INSERT INTO "lapTimes" VALUES ("1", "7", "1", "00:01:15.000");
INSERT INTO "lapTimes" VALUES ("1", "9", "1", "00:01:10.000");
INSERT INTO "qualifying" VALUES ("1", "1");
INSERT INTO "qualifying" VALUES ("2", "2");
INSERT INTO "qualifying" VALUES ("3", "3");
INSERT INTO "qualifying" VALUES ("4", "4");
INSERT INTO "qualifying" VALUES ("5", "5");
INSERT INTO "results" VALUES ("1", "5000");
INSERT INTO "results" VALUES ("2", "6000");
INSERT INTO "results" VALUES ("3", "7000");
INSERT INTO "results" VALUES ("4", "8000");
INSERT INTO "results" VALUES ("5", "9000");