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 "circuits" (
"circuitId" INT UNIQUE,
"country" TEXT,
"lat" FLOAT,
"lng" FLOAT,
PRIMARY KEY ("circuitId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"circuitId" INT,
"date" DATE,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

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



INSERT INTO "circuits" VALUES ("1", "Italy", "45.6156", "9.2811");
INSERT INTO "circuits" VALUES ("2", "United Kingdom", "52.0786", "-1.0169");
INSERT INTO "circuits" VALUES ("3", "Monaco", "43.7347", "7.4206");
INSERT INTO "circuits" VALUES ("4", "Belgium", "50.4372", "5.9714");
INSERT INTO "circuits" VALUES ("5", "Singapore", "1.2914", "103.8648");
INSERT INTO "races" VALUES ("101", "1", "2023-09-03");
INSERT INTO "races" VALUES ("102", "2", "2023-07-16");
INSERT INTO "races" VALUES ("103", "3", "2023-05-28");
INSERT INTO "races" VALUES ("104", "4", "2023-08-27");
INSERT INTO "races" VALUES ("105", "5", "2023-10-01");
INSERT INTO "results" VALUES ("1001", "101", "1:30.123", "1:29.488");
INSERT INTO "results" VALUES ("1002", "102", "1:28.999", "1:28.500");
INSERT INTO "results" VALUES ("1003", "103", "1:29.488", "1:29.488");
INSERT INTO "results" VALUES ("1004", "104", "1:30.500", "1:30.000");
INSERT INTO "results" VALUES ("1005", "105", "1:29.488", "1:29.488");