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 "constructors" (
"constructorId" INT,
"name" TEXT,
PRIMARY KEY ("constructorId")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"surname" TEXT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "qualifying" (
"qualifyId" INT,
"position" INT,
PRIMARY KEY ("qualifyId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"name" TEXT,
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 "constructors" VALUES ("1", "McLaren");
INSERT INTO "constructors" VALUES ("2", "Ferrari");
INSERT INTO "constructors" VALUES ("3", "Williams");
INSERT INTO "constructors" VALUES ("4", "Benetton");
INSERT INTO "constructors" VALUES ("5", "Tyrrell");
INSERT INTO "drivers" VALUES ("1", "Ayrton", "Senna");
INSERT INTO "drivers" VALUES ("2", "Alain", "Prost");
INSERT INTO "drivers" VALUES ("3", "Nigel", "Mansell");
INSERT INTO "drivers" VALUES ("4", "Gerhard", "Berger");
INSERT INTO "drivers" VALUES ("5", "Nelson", "Piquet");
INSERT INTO "drivers" VALUES ("6", "Riccardo", "Patrese");
INSERT INTO "drivers" VALUES ("7", "Alessandro", "Nannini");
INSERT INTO "drivers" VALUES ("8", "Jean", "Alesi");
INSERT INTO "drivers" VALUES ("9", "Mauricio", "Gugelmin");
INSERT INTO "drivers" VALUES ("10", "Stefano", "Modena");
INSERT INTO "qualifying" VALUES ("1", "1");
INSERT INTO "qualifying" VALUES ("2", "2");
INSERT INTO "qualifying" VALUES ("3", "3");
INSERT INTO "qualifying" VALUES ("4", "4");
INSERT INTO "qualifying" VALUES ("5", "5");
INSERT INTO "qualifying" VALUES ("6", "6");
INSERT INTO "qualifying" VALUES ("7", "7");
INSERT INTO "qualifying" VALUES ("8", "8");
INSERT INTO "qualifying" VALUES ("9", "9");
INSERT INTO "qualifying" VALUES ("10", "10");
INSERT INTO "races" VALUES ("1", "1989", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "1989", "Japanese Grand Prix");
INSERT INTO "races" VALUES ("3", "1989", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("4", "1990", "Australian Grand Prix");
INSERT INTO "races" VALUES ("5", "1988", "Australian Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "2");
INSERT INTO "results" VALUES ("3", "1", "3", "3", "3");
INSERT INTO "results" VALUES ("4", "1", "4", "4", "4");
INSERT INTO "results" VALUES ("5", "1", "5", "5", "5");
INSERT INTO "results" VALUES ("6", "2", "1", "1", "1");
INSERT INTO "results" VALUES ("7", "2", "2", "2", "2");
INSERT INTO "results" VALUES ("8", "3", "3", "1", "1");
INSERT INTO "results" VALUES ("9", "4", "4", "4", "1");
INSERT INTO "results" VALUES ("10", "5", "5", "4", "2");
INSERT INTO "results" VALUES ("11", "1", "6", "6", "6");
INSERT INTO "results" VALUES ("12", "1", "7", "7", "7");
INSERT INTO "results" VALUES ("13", "1", "8", "8", "8");
INSERT INTO "results" VALUES ("14", "1", "9", "9", "9");
INSERT INTO "results" VALUES ("15", "1", "10", "10", "10");