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 "circuits" (
"circuitId" INT UNIQUE,
"name" TEXT,
PRIMARY KEY ("circuitId")
);

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

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

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"circuitId" INT,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

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



INSERT INTO "circuits" VALUES ("1", "Sepang International Circuit");
INSERT INTO "circuits" VALUES ("2", "Monza");
INSERT INTO "circuits" VALUES ("3", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("4", "Circuit de Monaco");
INSERT INTO "circuits" VALUES ("5", "Suzuka Circuit");
INSERT INTO "constructors" VALUES ("1", "Ferrari");
INSERT INTO "constructors" VALUES ("2", "Mercedes");
INSERT INTO "constructors" VALUES ("3", "Red Bull");
INSERT INTO "constructors" VALUES ("4", "McLaren");
INSERT INTO "drivers" VALUES ("1", "Michael", "Schumacher", "German");
INSERT INTO "drivers" VALUES ("2", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("3", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso", "Spanish");
INSERT INTO "drivers" VALUES ("5", "Kimi", "Raikkonen", "Finnish");
INSERT INTO "races" VALUES ("1", "2000", "1");
INSERT INTO "races" VALUES ("2", "2001", "1");
INSERT INTO "races" VALUES ("3", "2002", "1");
INSERT INTO "races" VALUES ("4", "2003", "1");
INSERT INTO "races" VALUES ("5", "2004", "1");
INSERT INTO "races" VALUES ("6", "2005", "2");
INSERT INTO "races" VALUES ("7", "2006", "1");
INSERT INTO "races" VALUES ("8", "2007", "3");
INSERT INTO "races" VALUES ("9", "2008", "1");
INSERT INTO "races" VALUES ("10", "2009", "4");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1", "10.0");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "2", "6.0");
INSERT INTO "results" VALUES ("3", "2", "1", "1", "1", "10.0");
INSERT INTO "results" VALUES ("4", "2", "3", "2", "2", "6.0");
INSERT INTO "results" VALUES ("5", "3", "4", "1", "1", "10.0");
INSERT INTO "results" VALUES ("6", "3", "1", "2", "2", "6.0");
INSERT INTO "results" VALUES ("7", "4", "1", "1", "1", "10.0");
INSERT INTO "results" VALUES ("8", "4", "5", "2", "2", "8.0");
INSERT INTO "results" VALUES ("9", "5", "1", "1", "1", "10.0");
INSERT INTO "results" VALUES ("10", "5", "2", "3", "3", "4.0");
INSERT INTO "results" VALUES ("11", "6", "1", "5", "5", "2.0");
INSERT INTO "results" VALUES ("12", "7", "1", "2", "2", "8.0");
INSERT INTO "results" VALUES ("13", "7", "3", "1", "1", "10.0");
INSERT INTO "results" VALUES ("14", "8", "1", "1", "1", "10.0");
INSERT INTO "results" VALUES ("15", "9", "1", "1", "1", "10.0");
INSERT INTO "results" VALUES ("16", "9", "4", "2", "2", "8.0");