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 "drivers" (
"driverId" INT UNIQUE,
"surname" TEXT,
"url" TEXT,
PRIMARY KEY ("driverId")
);

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

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



INSERT INTO "drivers" VALUES ("1", "Hamilton", "https://en.wikipedia.org/wiki/Lewis_Hamilton");
INSERT INTO "drivers" VALUES ("2", "Raikkonen", "https://en.wikipedia.org/wiki/Kimi_R%C3%A4ikk%C3%B6nen");
INSERT INTO "drivers" VALUES ("3", "Massa", "https://en.wikipedia.org/wiki/Felipe_Massa");
INSERT INTO "drivers" VALUES ("4", "Button", "https://en.wikipedia.org/wiki/Jenson_Button");
INSERT INTO "races" VALUES ("101", "2008", "10", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2008", "11", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("103", "2008", "12", "Bahrain Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "10.0", "01:24:15.123", "5055123");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "8.0", "NULL", "5056123");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "6.0", "NULL", "5057123");
INSERT INTO "results" VALUES ("1004", "101", "4", "4", "5.0", "NULL", "5058123");
INSERT INTO "results" VALUES ("1005", "102", "2", "1", "10.0", "01:30:10.456", "5410456");
INSERT INTO "results" VALUES ("1006", "102", "1", "2", "8.0", "NULL", "5411456");
INSERT INTO "results" VALUES ("1007", "102", "4", "3", "6.0", "NULL", "5412456");
INSERT INTO "results" VALUES ("1008", "103", "3", "1", "10.0", "01:28:05.789", "5285789");
INSERT INTO "results" VALUES ("1009", "103", "1", "2", "8.0", "NULL", "5286789");
INSERT INTO "results" VALUES ("1010", "103", "2", "3", "6.0", "NULL", "5287789");