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

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

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

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

CREATE TABLE "status" (
"statusId" INT UNIQUE,
"status" TEXT,
PRIMARY KEY ("statusId")
);



INSERT INTO "constructors" VALUES ("1", "Mercedes");
INSERT INTO "constructors" VALUES ("2", "Red Bull");
INSERT INTO "constructors" VALUES ("3", "Ferrari");
INSERT INTO "drivers" VALUES ("1", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Verstappen");
INSERT INTO "drivers" VALUES ("3", "Leclerc");
INSERT INTO "drivers" VALUES ("4", "Bottas");
INSERT INTO "drivers" VALUES ("5", "Perez");
INSERT INTO "races" VALUES ("1", "Canadian Grand Prix");
INSERT INTO "races" VALUES ("2", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("3", "British Grand Prix");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Retired");
INSERT INTO "status" VALUES ("3", "Accident");
INSERT INTO "status" VALUES ("4", "Disqualified");
INSERT INTO "results" VALUES ("1", "1", "1", "2", "1");
INSERT INTO "results" VALUES ("2", "1", "2", "NULL", "3");
INSERT INTO "results" VALUES ("3", "1", "2", "NULL", "3");
INSERT INTO "results" VALUES ("4", "1", "2", "NULL", "3");
INSERT INTO "results" VALUES ("5", "1", "3", "1", "1");
INSERT INTO "results" VALUES ("6", "1", "4", "3", "1");
INSERT INTO "results" VALUES ("7", "1", "5", "NULL", "2");
INSERT INTO "results" VALUES ("8", "2", "1", "1", "1");
INSERT INTO "results" VALUES ("9", "2", "2", "2", "1");
INSERT INTO "results" VALUES ("10", "2", "3", "NULL", "3");
INSERT INTO "results" VALUES ("11", "2", "4", "3", "1");
INSERT INTO "results" VALUES ("12", "2", "5", "NULL", "4");
INSERT INTO "results" VALUES ("13", "3", "1", "1", "1");
INSERT INTO "results" VALUES ("14", "3", "2", "NULL", "2");
INSERT INTO "results" VALUES ("15", "3", "3", "2", "1");
INSERT INTO "results" VALUES ("16", "3", "4", "NULL", "3");
INSERT INTO "results" VALUES ("17", "3", "5", "3", "1");