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

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

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



INSERT INTO "drivers" VALUES ("1", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Button");
INSERT INTO "drivers" VALUES ("3", "Vettel");
INSERT INTO "drivers" VALUES ("4", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Massa");
INSERT INTO "races" VALUES ("101", "2009", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2009", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("103", "2009", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("104", "2009", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("105", "2009", "Spanish Grand Prix");
INSERT INTO "races" VALUES ("106", "2010", "Monaco Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "25.0", "1:24:15.123", "5");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "18.0", "1:24:17.456", "7");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "15.0", "1:24:20.789", "10");
INSERT INTO "results" VALUES ("1004", "102", "1", "1", "25.0", "1:30:10.234", "3");
INSERT INTO "results" VALUES ("1005", "102", "4", "2", "18.0", "1:30:12.345", "8");
INSERT INTO "results" VALUES ("1006", "102", "5", "3", "15.0", "1:30:15.678", "12");
INSERT INTO "results" VALUES ("1007", "103", "1", "2", "18.0", "1:28:05.987", "4");
INSERT INTO "results" VALUES ("1008", "103", "2", "1", "25.0", "1:28:03.456", "6");
INSERT INTO "results" VALUES ("1009", "103", "3", "3", "15.0", "1:28:10.123", "9");
INSERT INTO "results" VALUES ("1010", "104", "1", "1", "25.0", "1:32:20.456", "2");
INSERT INTO "results" VALUES ("1011", "104", "4", "3", "15.0", "1:32:25.789", "11");
INSERT INTO "results" VALUES ("1012", "104", "5", "2", "18.0", "1:32:22.345", "13");
INSERT INTO "results" VALUES ("1013", "105", "1", "1", "25.0", "1:25:30.123", "1");
INSERT INTO "results" VALUES ("1014", "105", "2", "3", "15.0", "1:25:35.456", "14");
INSERT INTO "results" VALUES ("1015", "105", "3", "2", "18.0", "1:25:33.789", "15");
INSERT INTO "results" VALUES ("1016", "106", "3", "1", "25.0", "1:27:40.123", "7");
INSERT INTO "results" VALUES ("1017", "106", "4", "2", "18.0", "1:27:42.456", "8");
INSERT INTO "results" VALUES ("1018", "106", "5", "3", "15.0", "1:27:45.789", "9");