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

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

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



INSERT INTO "drivers" VALUES ("1");
INSERT INTO "drivers" VALUES ("2");
INSERT INTO "drivers" VALUES ("3");
INSERT INTO "drivers" VALUES ("4");
INSERT INTO "drivers" VALUES ("5");
INSERT INTO "drivers" VALUES ("6");
INSERT INTO "drivers" VALUES ("7");
INSERT INTO "drivers" VALUES ("8");
INSERT INTO "drivers" VALUES ("9");
INSERT INTO "drivers" VALUES ("10");
INSERT INTO "races" VALUES ("1", "British Grand Prix", "1983-07-16");
INSERT INTO "races" VALUES ("2", "German Grand Prix", "1983-08-07");
INSERT INTO "races" VALUES ("3", "Monaco Grand Prix", "1983-05-15");
INSERT INTO "races" VALUES ("4", "Italian Grand Prix", "1983-09-11");
INSERT INTO "races" VALUES ("5", "French Grand Prix", "1983-04-17");
INSERT INTO "races" VALUES ("6", "Canadian Grand Prix", "1983-06-12");
INSERT INTO "races" VALUES ("7", "United States Grand Prix West", "1983-03-27");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1:35:02.539", "5702539");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "1:35:03.000", "5703000");
INSERT INTO "results" VALUES ("3", "1", "3", "3", "1:35:04.123", "5704123");
INSERT INTO "results" VALUES ("4", "1", "4", "4", "1:35:05.456", "5705456");
INSERT INTO "results" VALUES ("5", "1", "5", "5", "1:35:06.789", "5706789");
INSERT INTO "results" VALUES ("6", "1", "6", "0", "NULL", "NULL");
INSERT INTO "results" VALUES ("7", "1", "7", "0", "NULL", "NULL");
INSERT INTO "results" VALUES ("8", "1", "8", "0", "NULL", "NULL");
INSERT INTO "results" VALUES ("9", "2", "1", "1", "1:25:00.000", "5100000");
INSERT INTO "results" VALUES ("10", "2", "2", "2", "1:25:01.000", "5101000");
INSERT INTO "results" VALUES ("11", "3", "3", "1", "1:40:00.000", "6000000");
INSERT INTO "results" VALUES ("12", "3", "4", "2", "1:40:01.000", "6001000");
INSERT INTO "results" VALUES ("13", "4", "5", "1", "1:30:00.000", "5400000");
INSERT INTO "results" VALUES ("14", "4", "6", "2", "1:30:01.000", "5401000");
INSERT INTO "results" VALUES ("15", "5", "7", "1", "1:20:00.000", "4800000");
INSERT INTO "results" VALUES ("16", "5", "8", "2", "1:20:01.000", "4801000");
INSERT INTO "results" VALUES ("17", "6", "9", "1", "1:15:00.000", "4500000");
INSERT INTO "results" VALUES ("18", "6", "10", "2", "1:15:01.000", "4501000");
INSERT INTO "results" VALUES ("19", "1", "9", "6", "1:35:07.000", "5707000");
INSERT INTO "results" VALUES ("20", "1", "10", "0", "NULL", "NULL");