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



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", "Aston Martin");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("2", "Max", "Verstappen", "Dutch");
INSERT INTO "drivers" VALUES ("3", "Charles", "Leclerc", "Monegasque");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso", "Spanish");
INSERT INTO "drivers" VALUES ("5", "George", "Russell", "British");
INSERT INTO "drivers" VALUES ("6", "Sergio", "Perez", "Mexican");
INSERT INTO "drivers" VALUES ("7", "Carlos", "Sainz", "Spanish");
INSERT INTO "drivers" VALUES ("8", "Lando", "Norris", "British");
INSERT INTO "drivers" VALUES ("9", "Daniel", "Ricciardo", "Australian");
INSERT INTO "drivers" VALUES ("10", "Sebastian", "Vettel", "German");
INSERT INTO "races" VALUES ("1001", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("1002", "Saudi Arabian Grand Prix");
INSERT INTO "races" VALUES ("1003", "Australian Grand Prix");
INSERT INTO "races" VALUES ("1004", "Azerbaijan Grand Prix");
INSERT INTO "races" VALUES ("1005", "Miami Grand Prix");
INSERT INTO "races" VALUES ("1006", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("1007", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("1008", "Canadian Grand Prix");
INSERT INTO "races" VALUES ("1009", "British Grand Prix");
INSERT INTO "races" VALUES ("1010", "Hungarian Grand Prix");
INSERT INTO "results" VALUES ("1", "1001", "1", "5", "5");
INSERT INTO "results" VALUES ("2", "1001", "2", "1", "1");
INSERT INTO "results" VALUES ("3", "1001", "3", "3", "3");
INSERT INTO "results" VALUES ("4", "1002", "1", "2", "2");
INSERT INTO "results" VALUES ("5", "1002", "2", "1", "1");
INSERT INTO "results" VALUES ("6", "1002", "4", "3", "3");
INSERT INTO "results" VALUES ("7", "1003", "1", "6", "6");
INSERT INTO "results" VALUES ("8", "1003", "2", "1", "1");
INSERT INTO "results" VALUES ("9", "1003", "5", "4", "4");
INSERT INTO "results" VALUES ("10", "1004", "1", "1", "1");
INSERT INTO "results" VALUES ("11", "1004", "2", "2", "2");
INSERT INTO "results" VALUES ("12", "1004", "3", "5", "5");
INSERT INTO "results" VALUES ("13", "1005", "1", "3", "3");
INSERT INTO "results" VALUES ("14", "1005", "2", "1", "1");
INSERT INTO "results" VALUES ("15", "1005", "6", "2", "2");
INSERT INTO "results" VALUES ("16", "1006", "1", "4", "4");
INSERT INTO "results" VALUES ("17", "1006", "2", "1", "1");
INSERT INTO "results" VALUES ("18", "1006", "3", "6", "6");
INSERT INTO "results" VALUES ("19", "1007", "1", "2", "2");
INSERT INTO "results" VALUES ("20", "1007", "2", "1", "1");
INSERT INTO "results" VALUES ("21", "1007", "5", "3", "3");
INSERT INTO "results" VALUES ("22", "1008", "1", "1", "1");
INSERT INTO "results" VALUES ("23", "1008", "2", "2", "2");
INSERT INTO "results" VALUES ("24", "1008", "4", "3", "3");
INSERT INTO "results" VALUES ("25", "1009", "1", "3", "3");
INSERT INTO "results" VALUES ("26", "1009", "2", "1", "1");
INSERT INTO "results" VALUES ("27", "1009", "8", "2", "2");
INSERT INTO "results" VALUES ("28", "1010", "1", "1", "1");
INSERT INTO "results" VALUES ("29", "1010", "2", "2", "2");
INSERT INTO "results" VALUES ("30", "1010", "6", "3", "3");
INSERT INTO "results" VALUES ("31", "1001", "5", "4", "4");
INSERT INTO "results" VALUES ("32", "1001", "6", "2", "2");
INSERT INTO "results" VALUES ("33", "1002", "5", "5", "5");
INSERT INTO "results" VALUES ("34", "1002", "7", "4", "4");
INSERT INTO "results" VALUES ("35", "1003", "8", "2", "2");
INSERT INTO "results" VALUES ("36", "1003", "9", "3", "3");
INSERT INTO "results" VALUES ("37", "1004", "7", "3", "3");
INSERT INTO "results" VALUES ("38", "1004", "8", "4", "4");
INSERT INTO "results" VALUES ("39", "1005", "9", "4", "4");
INSERT INTO "results" VALUES ("40", "1005", "10", "5", "5");