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

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

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

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

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



INSERT INTO "races" VALUES ("1", "2023", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("2", "2023", "Saudi Arabian Grand Prix");
INSERT INTO "races" VALUES ("3", "2022", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("4", "2022", "British Grand Prix");
INSERT INTO "races" VALUES ("5", "2021", "Italian Grand Prix");
INSERT INTO "races" VALUES ("6", "2021", "Abu Dhabi Grand Prix");
INSERT INTO "drivers" VALUES ("1", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("2", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("3", "Charles", "Leclerc");
INSERT INTO "drivers" VALUES ("4", "Sergio", "Perez");
INSERT INTO "drivers" VALUES ("5", "Lando", "Norris");
INSERT INTO "drivers" VALUES ("6", "George", "Russell");
INSERT INTO "pitStops" VALUES ("1", "1", "1", "2.100");
INSERT INTO "pitStops" VALUES ("1", "2", "1", "2.500");
INSERT INTO "pitStops" VALUES ("1", "3", "1", "2.300");
INSERT INTO "pitStops" VALUES ("2", "1", "1", "2.200");
INSERT INTO "pitStops" VALUES ("2", "4", "1", "2.000");
INSERT INTO "pitStops" VALUES ("3", "3", "1", "3.500");
INSERT INTO "pitStops" VALUES ("3", "5", "1", "2.800");
INSERT INTO "pitStops" VALUES ("4", "2", "1", "2.600");
INSERT INTO "pitStops" VALUES ("4", "6", "1", "2.400");
INSERT INTO "pitStops" VALUES ("5", "1", "1", "2.700");
INSERT INTO "pitStops" VALUES ("5", "3", "1", "2.900");
INSERT INTO "pitStops" VALUES ("6", "2", "1", "3.100");
INSERT INTO "pitStops" VALUES ("6", "4", "1", "4.000");
INSERT INTO "pitStops" VALUES ("1", "1", "2", "2.050");
INSERT INTO "pitStops" VALUES ("1", "2", "2", "2.450");
INSERT INTO "pitStops" VALUES ("3", "3", "2", "2.200");
INSERT INTO "pitStops" VALUES ("4", "2", "2", "2.550");
INSERT INTO "pitStops" VALUES ("6", "4", "2", "5.000");
INSERT INTO "pitStops" VALUES ("6", "2", "2", "10.000");
INSERT INTO "constructors" VALUES ("1", "Red Bull Racing");
INSERT INTO "constructors" VALUES ("2", "Mercedes");
INSERT INTO "constructors" VALUES ("3", "Ferrari");
INSERT INTO "constructors" VALUES ("4", "McLaren");
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 "qualifying" VALUES ("6", "6");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");
INSERT INTO "results" VALUES ("4", "4");
INSERT INTO "results" VALUES ("5", "5");
INSERT INTO "results" VALUES ("6", "6");