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 "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"milliseconds" INT,
PRIMARY KEY ("raceId", "driverId", "lap")
);

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

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

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



INSERT INTO "driverStandings" VALUES ("1", "120.0");
INSERT INTO "driverStandings" VALUES ("2", "110.0");
INSERT INTO "driverStandings" VALUES ("3", "95.0");
INSERT INTO "driverStandings" VALUES ("4", "80.0");
INSERT INTO "races" VALUES ("101", "1972");
INSERT INTO "races" VALUES ("102", "1973");
INSERT INTO "races" VALUES ("103", "1974");
INSERT INTO "races" VALUES ("104", "1975");
INSERT INTO "races" VALUES ("105", "1970");
INSERT INTO "results" VALUES ("201", "101", "1", "01:30:15.123", "5415123");
INSERT INTO "results" VALUES ("202", "101", "2", "01:31:00.000", "5460000");
INSERT INTO "results" VALUES ("203", "102", "1", "01:28:45.500", "5325500");
INSERT INTO "results" VALUES ("204", "102", "3", "01:29:30.000", "5370000");
INSERT INTO "results" VALUES ("205", "103", "1", "01:32:10.250", "5530250");
INSERT INTO "results" VALUES ("206", "103", "4", "NULL", "NULL");
INSERT INTO "results" VALUES ("207", "104", "1", "01:29:00.000", "5340000");
INSERT INTO "results" VALUES ("208", "105", "1", "01:31:30.750", "5490750");
INSERT INTO "results" VALUES ("209", "105", "2", "01:32:00.000", "5520000");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "89000");
INSERT INTO "lapTimes" VALUES ("102", "2", "1", "88000");
INSERT INTO "lapTimes" VALUES ("102", "2", "2", "87000");
INSERT INTO "lapTimes" VALUES ("103", "3", "1", "91000");
INSERT INTO "lapTimes" VALUES ("103", "3", "2", "92000");
INSERT INTO "lapTimes" VALUES ("105", "4", "1", "93000");
INSERT INTO "lapTimes" VALUES ("105", "4", "2", "94000");
INSERT INTO "qualifying" VALUES ("301", "1");
INSERT INTO "qualifying" VALUES ("302", "2");
INSERT INTO "qualifying" VALUES ("303", "3");
INSERT INTO "qualifying" VALUES ("304", "4");