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

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"name" TEXT,
"date" DATE,
PRIMARY KEY ("raceId")
);

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 "drivers" VALUES ("1", "Fernando", "Alonso", "Spanish");
INSERT INTO "drivers" VALUES ("2", "Michael", "Schumacher", "German");
INSERT INTO "drivers" VALUES ("3", "Kimi", "Raikkonen", "Finnish");
INSERT INTO "drivers" VALUES ("4", "Felipe", "Massa", "Brazilian");
INSERT INTO "drivers" VALUES ("5", "Jenson", "Button", "British");
INSERT INTO "races" VALUES ("101", "2006", "San Marino Grand Prix", "2006-04-23");
INSERT INTO "races" VALUES ("102", "2006", "Australian Grand Prix", "2006-03-26");
INSERT INTO "races" VALUES ("103", "2006", "Monaco Grand Prix", "2006-05-28");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "10.0");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "8.0");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "6.0");
INSERT INTO "results" VALUES ("1004", "101", "4", "4", "5.0");
INSERT INTO "results" VALUES ("1005", "101", "5", "5", "4.0");
INSERT INTO "results" VALUES ("1006", "102", "3", "1", "10.0");
INSERT INTO "results" VALUES ("1007", "102", "1", "2", "8.0");
INSERT INTO "results" VALUES ("1008", "102", "2", "3", "6.0");
INSERT INTO "results" VALUES ("1009", "103", "4", "1", "10.0");
INSERT INTO "results" VALUES ("1010", "103", "5", "2", "8.0");
INSERT INTO "results" VALUES ("1011", "103", "1", "3", "6.0");