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 "driverStandings" (
"driverStandingsId" INT,
"position" INT,
PRIMARY KEY ("driverStandingsId")
);

CREATE TABLE "constructors" (
"constructorId" INT,
"name" TEXT,
PRIMARY KEY ("constructorId")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"driverRef" 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,
"constructorId" INT,
"position" INT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId"),
FOREIGN KEY ("constructorId") REFERENCES "constructors"("constructorId")
);



INSERT INTO "driverStandings" VALUES ("1", "1");
INSERT INTO "driverStandings" VALUES ("2", "2");
INSERT INTO "driverStandings" VALUES ("3", "3");
INSERT INTO "constructors" VALUES ("1", "Ferrari");
INSERT INTO "constructors" VALUES ("2", "McLaren");
INSERT INTO "constructors" VALUES ("3", "Renault");
INSERT INTO "drivers" VALUES ("1", "hamilton");
INSERT INTO "drivers" VALUES ("2", "alonso");
INSERT INTO "drivers" VALUES ("3", "raikkonen");
INSERT INTO "races" VALUES ("1", "2007", "Canadian Grand Prix");
INSERT INTO "races" VALUES ("2", "2007", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("3", "2006", "Canadian Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1", "2", "1");
INSERT INTO "results" VALUES ("2", "1", "2", "3", "2");
INSERT INTO "results" VALUES ("3", "1", "3", "1", "3");
INSERT INTO "results" VALUES ("4", "2", "2", "3", "1");
INSERT INTO "results" VALUES ("5", "3", "3", "1", "1");