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

CREATE TABLE "constructors" (
"constructorId" INT UNIQUE,
"nationality" TEXT,
PRIMARY KEY ("constructorId")
);

CREATE TABLE "drivers" (
"driverId" INT,
"nationality" TEXT,
PRIMARY KEY ("driverId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"constructorId" INT,
"position" INT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId"),
FOREIGN KEY ("constructorId") REFERENCES "constructors"("constructorId")
);



INSERT INTO "constructors" VALUES ("1", "French");
INSERT INTO "constructors" VALUES ("2", "German");
INSERT INTO "constructors" VALUES ("3", "Italian");
INSERT INTO "constructors" VALUES ("4", "French");
INSERT INTO "constructors" VALUES ("5", "British");
INSERT INTO "drivers" VALUES ("10", "French");
INSERT INTO "drivers" VALUES ("11", "German");
INSERT INTO "drivers" VALUES ("12", "Italian");
INSERT INTO "drivers" VALUES ("13", "British");
INSERT INTO "drivers" VALUES ("14", "French");
INSERT INTO "races" VALUES ("100", "2022");
INSERT INTO "races" VALUES ("101", "2023");
INSERT INTO "results" VALUES ("1000", "100", "10", "1", "1");
INSERT INTO "results" VALUES ("1001", "100", "11", "2", "2");
INSERT INTO "results" VALUES ("1002", "100", "12", "3", "3");
INSERT INTO "results" VALUES ("1003", "100", "13", "5", "4");
INSERT INTO "results" VALUES ("1004", "101", "14", "4", "1");
INSERT INTO "results" VALUES ("1005", "101", "10", "1", "2");
INSERT INTO "results" VALUES ("1006", "101", "11", "2", "3");
INSERT INTO "lapTimes" VALUES ("100", "10", "51");
INSERT INTO "lapTimes" VALUES ("100", "10", "52");
INSERT INTO "lapTimes" VALUES ("100", "11", "30");
INSERT INTO "lapTimes" VALUES ("100", "11", "40");
INSERT INTO "lapTimes" VALUES ("101", "14", "60");
INSERT INTO "lapTimes" VALUES ("101", "14", "61");
INSERT INTO "lapTimes" VALUES ("101", "10", "45");
INSERT INTO "lapTimes" VALUES ("101", "10", "49");
INSERT INTO "lapTimes" VALUES ("100", "12", "55");
INSERT INTO "lapTimes" VALUES ("100", "12", "56");
INSERT INTO "lapTimes" VALUES ("100", "13", "51");
INSERT INTO "lapTimes" VALUES ("100", "13", "52");