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 "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,
"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", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("3", "Monza Circuit");
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 "races" VALUES ("1", "2000", "1");
INSERT INTO "races" VALUES ("2", "2001", "1");
INSERT INTO "races" VALUES ("3", "2002", "1");
INSERT INTO "races" VALUES ("4", "2000", "2");
INSERT INTO "races" VALUES ("5", "2001", "3");
INSERT INTO "races" VALUES ("6", "2003", "1");
INSERT INTO "races" VALUES ("7", "2004", "1");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "10.0");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "8.0");
INSERT INTO "results" VALUES ("3", "1", "3", "3", "6.0");
INSERT INTO "results" VALUES ("4", "2", "1", "1", "10.0");
INSERT INTO "results" VALUES ("5", "2", "4", "2", "8.0");
INSERT INTO "results" VALUES ("6", "2", "3", "3", "6.0");
INSERT INTO "results" VALUES ("7", "3", "2", "1", "10.0");
INSERT INTO "results" VALUES ("8", "3", "1", "2", "8.0");
INSERT INTO "results" VALUES ("9", "3", "4", "3", "6.0");
INSERT INTO "results" VALUES ("10", "4", "4", "1", "10.0");
INSERT INTO "results" VALUES ("11", "4", "1", "2", "8.0");
INSERT INTO "results" VALUES ("12", "5", "3", "1", "10.0");
INSERT INTO "results" VALUES ("13", "5", "2", "2", "8.0");
INSERT INTO "results" VALUES ("14", "6", "1", "1", "10.0");
INSERT INTO "results" VALUES ("15", "6", "3", "2", "8.0");
INSERT INTO "results" VALUES ("16", "7", "1", "1", "10.0");
INSERT INTO "results" VALUES ("17", "7", "2", "2", "8.0");