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")
);

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

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

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

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"milliseconds" INT,
"fastestLap" INT,
"fastestLapTime" TEXT,
"fastestLapSpeed" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);



INSERT INTO "lapTimes" VALUES ("1", "1", "1", "1:20.000");
INSERT INTO "lapTimes" VALUES ("1", "1", "2", "1:19.500");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "1:21.000");
INSERT INTO "lapTimes" VALUES ("2", "1", "1", "1:22.000");
INSERT INTO "lapTimes" VALUES ("2", "1", "2", "1:21.200");
INSERT INTO "lapTimes" VALUES ("3", "3", "1", "1:18.000");
INSERT INTO "lapTimes" VALUES ("3", "3", "2", "1:17.800");
INSERT INTO "lapTimes" VALUES ("4", "1", "1", "1:20.500");
INSERT INTO "lapTimes" VALUES ("4", "1", "2", "1:19.800");
INSERT INTO "lapTimes" VALUES ("5", "3", "1", "1:17.500");
INSERT INTO "lapTimes" VALUES ("5", "3", "2", "1:17.200");
INSERT INTO "circuits" VALUES ("1", "Circuit de Catalunya");
INSERT INTO "circuits" VALUES ("2", "Monza");
INSERT INTO "circuits" VALUES ("3", "Spa-Francorchamps");
INSERT INTO "circuits" VALUES ("4", "Silverstone");
INSERT INTO "circuits" VALUES ("5", "Suzuka");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Michael", "Schumacher");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Max", "Verstappen");
INSERT INTO "qualifying" VALUES ("1", "1:18.000");
INSERT INTO "qualifying" VALUES ("2", "1:19.000");
INSERT INTO "qualifying" VALUES ("3", "1:17.000");
INSERT INTO "qualifying" VALUES ("4", "1:18.500");
INSERT INTO "qualifying" VALUES ("5", "1:17.300");
INSERT INTO "races" VALUES ("1", "2004", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("2", "2005", "Italian Grand Prix");
INSERT INTO "races" VALUES ("3", "2006", "Belgian Grand Prix");
INSERT INTO "races" VALUES ("4", "2007", "British Grand Prix");
INSERT INTO "races" VALUES ("5", "2008", "Japanese Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1", "5000000", "2", "1:19.500", "200.0");
INSERT INTO "results" VALUES ("2", "1", "2", "5005000", "1", "1:21.000", "195.0");
INSERT INTO "results" VALUES ("3", "2", "1", "5100000", "2", "1:21.200", "190.0");
INSERT INTO "results" VALUES ("4", "3", "3", "4900000", "2", "1:17.800", "210.0");
INSERT INTO "results" VALUES ("5", "4", "1", "5050000", "2", "1:19.800", "198.0");
INSERT INTO "results" VALUES ("6", "5", "3", "4850000", "2", "1:17.200", "212.0");
INSERT INTO "results" VALUES ("7", "3", "1", "4950000", "1", "1:18.500", "205.0");
INSERT INTO "results" VALUES ("8", "5", "1", "4900000", "1", "1:18.000", "208.0");