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,
"forename" TEXT,
"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,
"constructorId" INT,
"position" INT,
"statusId" INT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId"),
FOREIGN KEY ("constructorId") REFERENCES "constructors"("constructorId"),
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 "constructors" VALUES ("4", "McLaren");
INSERT INTO "constructors" VALUES ("5", "Alpine");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("3", "Charles", "Leclerc");
INSERT INTO "drivers" VALUES ("4", "Sergio", "Perez");
INSERT INTO "drivers" VALUES ("5", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("6", "Daniel", "Ricciardo");
INSERT INTO "drivers" VALUES ("7", "Lando", "Norris");
INSERT INTO "drivers" VALUES ("8", "Carlos", "Sainz");
INSERT INTO "drivers" VALUES ("9", "George", "Russell");
INSERT INTO "drivers" VALUES ("10", "Esteban", "Ocon");
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 "races" VALUES ("4", "Italian Grand Prix");
INSERT INTO "races" VALUES ("5", "Japanese Grand Prix");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Engine");
INSERT INTO "status" VALUES ("3", "Accident");
INSERT INTO "status" VALUES ("4", "Collision");
INSERT INTO "status" VALUES ("5", "Gearbox");
INSERT INTO "status" VALUES ("6", "Spun off");
INSERT INTO "status" VALUES ("7", "Hydraulics");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1", "1");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "2", "1");
INSERT INTO "results" VALUES ("3", "1", "3", "3", "3", "1");
INSERT INTO "results" VALUES ("4", "1", "4", "2", "4", "1");
INSERT INTO "results" VALUES ("5", "1", "5", "5", "5", "1");
INSERT INTO "results" VALUES ("6", "1", "6", "4", "6", "3");
INSERT INTO "results" VALUES ("7", "1", "7", "4", "7", "3");
INSERT INTO "results" VALUES ("8", "1", "8", "3", "8", "3");
INSERT INTO "results" VALUES ("9", "1", "9", "1", "9", "3");
INSERT INTO "results" VALUES ("10", "1", "10", "5", "10", "3");
INSERT INTO "results" VALUES ("11", "2", "1", "1", "1", "1");
INSERT INTO "results" VALUES ("12", "2", "2", "2", "2", "1");
INSERT INTO "results" VALUES ("13", "2", "3", "3", "3", "1");
INSERT INTO "results" VALUES ("14", "2", "6", "4", "4", "3");
INSERT INTO "results" VALUES ("15", "2", "7", "4", "5", "1");
INSERT INTO "results" VALUES ("16", "3", "1", "1", "1", "1");
INSERT INTO "results" VALUES ("17", "3", "2", "2", "2", "1");
INSERT INTO "results" VALUES ("18", "3", "3", "3", "3", "1");
INSERT INTO "results" VALUES ("19", "3", "6", "4", "4", "3");
INSERT INTO "results" VALUES ("20", "3", "7", "4", "5", "3");
INSERT INTO "results" VALUES ("21", "1", "6", "4", "NULL", "3");
INSERT INTO "results" VALUES ("22", "1", "7", "4", "NULL", "3");
INSERT INTO "results" VALUES ("23", "1", "8", "3", "NULL", "3");
INSERT INTO "results" VALUES ("24", "1", "9", "1", "NULL", "3");
INSERT INTO "results" VALUES ("25", "1", "10", "5", "NULL", "3");
INSERT INTO "results" VALUES ("26", "1", "6", "4", "NULL", "3");
INSERT INTO "results" VALUES ("27", "1", "7", "4", "NULL", "3");
INSERT INTO "results" VALUES ("28", "1", "8", "3", "NULL", "3");
INSERT INTO "results" VALUES ("29", "1", "9", "1", "NULL", "3");
INSERT INTO "results" VALUES ("30", "1", "10", "5", "NULL", "3");
INSERT INTO "results" VALUES ("31", "1", "6", "4", "NULL", "3");
INSERT INTO "results" VALUES ("32", "1", "7", "4", "NULL", "3");
INSERT INTO "results" VALUES ("33", "1", "8", "3", "NULL", "3");
INSERT INTO "results" VALUES ("34", "1", "9", "1", "NULL", "3");
INSERT INTO "results" VALUES ("35", "1", "10", "5", "NULL", "3");
INSERT INTO "results" VALUES ("36", "1", "6", "4", "NULL", "3");
INSERT INTO "results" VALUES ("37", "1", "7", "4", "NULL", "3");
INSERT INTO "results" VALUES ("38", "1", "8", "3", "NULL", "3");
INSERT INTO "results" VALUES ("39", "1", "9", "1", "NULL", "3");
INSERT INTO "results" VALUES ("40", "1", "10", "5", "NULL", "3");
INSERT INTO "results" VALUES ("41", "1", "6", "4", "NULL", "3");
INSERT INTO "results" VALUES ("42", "1", "7", "4", "NULL", "3");
INSERT INTO "results" VALUES ("43", "1", "8", "3", "NULL", "3");
INSERT INTO "results" VALUES ("44", "1", "9", "1", "NULL", "3");
INSERT INTO "results" VALUES ("45", "1", "10", "5", "NULL", "3");