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

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"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", "15");
INSERT INTO "driverStandings" VALUES ("3", "25");
INSERT INTO "constructors" VALUES ("1", "Red Bull Racing");
INSERT INTO "constructors" VALUES ("2", "McLaren");
INSERT INTO "constructors" VALUES ("3", "Williams");
INSERT INTO "drivers" VALUES ("1", "Alex", "Yoong");
INSERT INTO "drivers" VALUES ("2", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("3", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("4", "Kimi", "Raikkonen");
INSERT INTO "races" VALUES ("1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("3", "British Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1", "2", "18");
INSERT INTO "results" VALUES ("2", "2", "1", "2", "21");
INSERT INTO "results" VALUES ("3", "3", "1", "2", "19");
INSERT INTO "results" VALUES ("4", "1", "2", "1", "1");
INSERT INTO "results" VALUES ("5", "2", "3", "3", "5");
INSERT INTO "results" VALUES ("6", "3", "4", "3", "7");