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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" 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", "Melbourne Grand Prix Circuit");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit");
INSERT INTO "circuits" VALUES ("3", "Shanghai International Circuit");
INSERT INTO "circuits" VALUES ("4", "Bahrain International Circuit");
INSERT INTO "circuits" VALUES ("5", "Circuit de Catalunya");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("2", "Felipe", "Massa", "Brazilian");
INSERT INTO "drivers" VALUES ("3", "Kimi", "Räikkönen", "Finnish");
INSERT INTO "drivers" VALUES ("4", "Robert", "Kubica", "Polish");
INSERT INTO "drivers" VALUES ("5", "Fernando", "Alonso", "Spanish");
INSERT INTO "drivers" VALUES ("6", "Sebastian", "Vettel", "German");
INSERT INTO "drivers" VALUES ("7", "Jenson", "Button", "British");
INSERT INTO "races" VALUES ("1", "2008", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "2008", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("3", "2008", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("4", "2009", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("5", "2008", "Brazilian Grand Prix");
INSERT INTO "races" VALUES ("6", "2007", "Chinese Grand Prix");
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", "3", "1", "1", "10.0");
INSERT INTO "results" VALUES ("4", "3", "2", "2", "8.0");
INSERT INTO "results" VALUES ("5", "3", "3", "3", "6.0");
INSERT INTO "results" VALUES ("6", "4", "1", "6", "3.0");
INSERT INTO "results" VALUES ("7", "5", "1", "5", "4.0");
INSERT INTO "results" VALUES ("8", "6", "1", "0", "0.0");
INSERT INTO "results" VALUES ("9", "3", "4", "4", "5.0");
INSERT INTO "results" VALUES ("10", "3", "5", "0", "0.0");