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 "drivers" (
"driverId" INT UNIQUE,
"driverRef" TEXT,
"number" INT,
"forename" TEXT,
"surname" TEXT,
PRIMARY KEY ("driverId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"constructorId" INT,
"position" INT,
"positionText" TEXT,
"points" FLOAT,
"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,
"status" TEXT,
PRIMARY KEY ("statusId")
);



INSERT INTO "drivers" VALUES ("1", "Hamilton", "44", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "vettel", "5", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "verstappen", "33", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("4", "bottas", "77", "Valtteri", "Bottas");
INSERT INTO "drivers" VALUES ("5", "ricciardo", "3", "Daniel", "Ricciardo");
INSERT INTO "races" VALUES ("101", "2023", "1", "Bahrain Grand Prix", "2023-03-05");
INSERT INTO "races" VALUES ("102", "2023", "2", "Saudi Arabian Grand Prix", "2023-03-19");
INSERT INTO "races" VALUES ("103", "2023", "3", "Australian Grand Prix", "2023-04-02");
INSERT INTO "races" VALUES ("104", "2023", "4", "Azerbaijan Grand Prix", "2023-04-30");
INSERT INTO "races" VALUES ("105", "2023", "5", "Miami Grand Prix", "2023-05-07");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Accident");
INSERT INTO "status" VALUES ("3", "Mechanical Failure");
INSERT INTO "status" VALUES ("4", "Disqualified");
INSERT INTO "status" VALUES ("5", "Retired");
INSERT INTO "results" VALUES ("1001", "101", "1", "10", "1", "1", "25.0", "1");
INSERT INTO "results" VALUES ("1002", "101", "2", "11", "2", "2", "18.0", "1");
INSERT INTO "results" VALUES ("1003", "101", "3", "12", "3", "3", "15.0", "1");
INSERT INTO "results" VALUES ("1004", "102", "1", "10", "2", "2", "18.0", "1");
INSERT INTO "results" VALUES ("1005", "102", "4", "10", "1", "1", "25.0", "1");
INSERT INTO "results" VALUES ("1006", "102", "5", "13", "5", "5", "10.0", "1");
INSERT INTO "results" VALUES ("1007", "103", "1", "10", "3", "3", "15.0", "1");
INSERT INTO "results" VALUES ("1008", "103", "3", "12", "1", "1", "25.0", "1");
INSERT INTO "results" VALUES ("1009", "103", "2", "11", "4", "4", "12.0", "1");
INSERT INTO "results" VALUES ("1010", "104", "1", "10", "1", "1", "25.0", "1");
INSERT INTO "results" VALUES ("1011", "104", "4", "10", "3", "3", "15.0", "1");
INSERT INTO "results" VALUES ("1012", "104", "5", "13", "7", "7", "6.0", "1");
INSERT INTO "results" VALUES ("1013", "105", "1", "10", "15", "15", "0.0", "5");
INSERT INTO "results" VALUES ("1014", "105", "3", "12", "1", "1", "25.0", "1");
INSERT INTO "results" VALUES ("1015", "105", "2", "11", "2", "2", "18.0", "1");