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

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

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



INSERT INTO "drivers" VALUES ("1", "Michael", "Schumacher", "German");
INSERT INTO "drivers" VALUES ("2", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("3", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso", "Spanish");
INSERT INTO "drivers" VALUES ("5", "Kimi", "Raikkonen", "Finnish");
INSERT INTO "drivers" VALUES ("6", "Alex", "Yoong", "Malaysian");
INSERT INTO "races" VALUES ("101", "2000", "1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2000", "2", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("103", "2001", "1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("104", "2001", "2", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("105", "2002", "1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("106", "2002", "2", "Brazilian Grand Prix");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "5400000", "1", "1:30.500");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "5405000", "0", "NULL");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "5410000", "0", "NULL");
INSERT INTO "results" VALUES ("1004", "102", "1", "2", "5300000", "0", "NULL");
INSERT INTO "results" VALUES ("1005", "102", "4", "1", "5290000", "1", "1:29.800");
INSERT INTO "results" VALUES ("1006", "102", "6", "5", "5500000", "0", "NULL");
INSERT INTO "results" VALUES ("1007", "103", "1", "3", "5350000", "0", "NULL");
INSERT INTO "results" VALUES ("1008", "103", "5", "1", "5330000", "1", "1:29.200");
INSERT INTO "results" VALUES ("1009", "104", "1", "1", "5200000", "1", "1:28.900");
INSERT INTO "results" VALUES ("1010", "104", "2", "2", "5210000", "0", "NULL");
INSERT INTO "results" VALUES ("1011", "105", "1", "1", "5100000", "1", "1:28.500");
INSERT INTO "results" VALUES ("1012", "105", "3", "2", "5120000", "0", "NULL");
INSERT INTO "results" VALUES ("1013", "106", "1", "2", "5150000", "0", "NULL");
INSERT INTO "results" VALUES ("1014", "106", "4", "1", "5140000", "1", "1:28.700");
INSERT INTO "results" VALUES ("1015", "106", "6", "6", "5600000", "0", "NULL");