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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"position" INT,
PRIMARY KEY ("qualifyId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"fastestLapTime" TEXT,
"fastestLapSpeed" TEXT,
"statusId" 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", "80.0");
INSERT INTO "drivers" VALUES ("101", "Paul", "di Resta");
INSERT INTO "drivers" VALUES ("102", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("103", "Sebastian", "Vettel");
INSERT INTO "qualifying" VALUES ("201", "1");
INSERT INTO "qualifying" VALUES ("202", "2");
INSERT INTO "qualifying" VALUES ("203", "3");
INSERT INTO "races" VALUES ("852");
INSERT INTO "races" VALUES ("853");
INSERT INTO "races" VALUES ("854");
INSERT INTO "races" VALUES ("855");
INSERT INTO "results" VALUES ("301", "852", "101", "5", "1:25.123", "210.5", "1");
INSERT INTO "results" VALUES ("302", "853", "101", "3", "1:24.500", "215.0", "1");
INSERT INTO "results" VALUES ("303", "854", "101", "4", "1:25.000", "212.0", "1");
INSERT INTO "results" VALUES ("304", "855", "101", "6", "1:26.000", "NULL", "2");
INSERT INTO "results" VALUES ("305", "853", "102", "1", "1:24.200", "217.0", "1");
INSERT INTO "results" VALUES ("306", "854", "102", "2", "1:24.800", "213.5", "1");
INSERT INTO "results" VALUES ("307", "853", "103", "2", "1:24.300", "215.0", "1");
INSERT INTO "results" VALUES ("308", "854", "103", "3", "1:25.100", "212.0", "1");
INSERT INTO "results" VALUES ("309", "852", "101", "7", "1:25.500", "210.5", "1");