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,
"name" TEXT,
"date" DATE,
PRIMARY KEY ("raceId")
);

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



INSERT INTO "drivers" VALUES ("1", "Ayrton", "Senna", "Brazilian");
INSERT INTO "drivers" VALUES ("2", "Alain", "Prost", "French");
INSERT INTO "drivers" VALUES ("3", "Nigel", "Mansell", "British");
INSERT INTO "drivers" VALUES ("4", "Riccardo", "Patrese", "Italian");
INSERT INTO "drivers" VALUES ("5", "Gerhard", "Berger", "Austrian");
INSERT INTO "drivers" VALUES ("6", "Thierry", "Boutsen", "Belgian");
INSERT INTO "races" VALUES ("101", "1989", "Australian Grand Prix", "1989-11-05");
INSERT INTO "races" VALUES ("102", "1989", "Japanese Grand Prix", "1989-10-22");
INSERT INTO "races" VALUES ("103", "1990", "Australian Grand Prix", "1990-03-11");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "2");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "3");
INSERT INTO "results" VALUES ("1004", "101", "4", "4", "5");
INSERT INTO "results" VALUES ("1005", "101", "5", "5", "4");
INSERT INTO "results" VALUES ("1006", "101", "6", "6", "6");
INSERT INTO "results" VALUES ("1007", "102", "1", "3", "2");
INSERT INTO "results" VALUES ("1008", "102", "2", "1", "1");
INSERT INTO "results" VALUES ("1009", "102", "3", "2", "3");
INSERT INTO "results" VALUES ("1010", "102", "4", "4", "4");
INSERT INTO "results" VALUES ("1011", "103", "1", "2", "1");
INSERT INTO "results" VALUES ("1012", "103", "2", "1", "2");
INSERT INTO "results" VALUES ("1013", "103", "3", "4", "3");
INSERT INTO "results" VALUES ("1014", "103", "4", "3", "4");