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 UNIQUE,
PRIMARY KEY ("constructorId")
);

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

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"time" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);



INSERT INTO "constructors" VALUES ("1");
INSERT INTO "constructors" VALUES ("2");
INSERT INTO "constructors" VALUES ("3");
INSERT INTO "drivers" VALUES ("10", "Rossi", "Italian");
INSERT INTO "drivers" VALUES ("11", "Bianchi", "Italian");
INSERT INTO "drivers" VALUES ("12", "Verdi", "Italian");
INSERT INTO "drivers" VALUES ("13", "Smith", "British");
INSERT INTO "drivers" VALUES ("14", "Johnson", "American");
INSERT INTO "drivers" VALUES ("15", "Garcia", "Spanish");
INSERT INTO "races" VALUES ("100", "2024-05-01");
INSERT INTO "races" VALUES ("101", "2024-05-15");
INSERT INTO "results" VALUES ("1000", "100", "10", "NULL");
INSERT INTO "results" VALUES ("1001", "100", "11", "1:30:45");
INSERT INTO "results" VALUES ("1002", "100", "12", "NULL");
INSERT INTO "results" VALUES ("1003", "100", "13", "1:28:30");
INSERT INTO "results" VALUES ("1004", "101", "10", "1:29:10");
INSERT INTO "results" VALUES ("1005", "101", "11", "NULL");
INSERT INTO "results" VALUES ("1006", "101", "14", "1:31:00");
INSERT INTO "results" VALUES ("1007", "101", "15", "1:32:15");