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 "driverStandings" (
"driverStandingsId" INT,
"points" FLOAT,
PRIMARY KEY ("driverStandingsId")
);

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

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

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



INSERT INTO "driverStandings" VALUES ("1", "120.5");
INSERT INTO "driverStandings" VALUES ("2", "95.0");
INSERT INTO "driverStandings" VALUES ("3", "110.0");
INSERT INTO "drivers" VALUES ("101", "Bruce", "McLaren", "New Zealand");
INSERT INTO "drivers" VALUES ("102", "Jack", "Brabham", "Australia");
INSERT INTO "drivers" VALUES ("103", "Jim", "Clark", "United Kingdom");
INSERT INTO "races" VALUES ("742");
INSERT INTO "races" VALUES ("743");
INSERT INTO "races" VALUES ("744");
INSERT INTO "results" VALUES ("201", "742", "101", "2", "1:32:15.123", "5535123");
INSERT INTO "results" VALUES ("202", "743", "101", "1", "1:30:45.678", "5445678");
INSERT INTO "results" VALUES ("203", "743", "102", "2", "1:31:10.234", "5470234");
INSERT INTO "results" VALUES ("204", "743", "103", "3", "1:31:45.000", "5505000");
INSERT INTO "results" VALUES ("205", "744", "103", "1", "1:29:55.321", "5395321");