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

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

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"name" TEXT,
"date" DATE,
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")
);



INSERT INTO "circuits" VALUES ("1", "Italy");
INSERT INTO "circuits" VALUES ("2", "United Kingdom");
INSERT INTO "circuits" VALUES ("3", "Monaco");
INSERT INTO "drivers" VALUES ("101", "Alice", "Smith", "2000-05-15", "British");
INSERT INTO "drivers" VALUES ("102", "Bob", "Johnson", "1995-08-20", "American");
INSERT INTO "drivers" VALUES ("103", "Clara", "Zhang", "2002-11-30", "Chinese");
INSERT INTO "drivers" VALUES ("104", "David", "Lee", "1998-01-10", "Australian");
INSERT INTO "drivers" VALUES ("105", "Eva", "Martinez", "2002-11-30", "Spanish");
INSERT INTO "races" VALUES ("201", "Monaco Grand Prix", "2018-05-27");
INSERT INTO "races" VALUES ("202", "British Grand Prix", "2019-07-14");
INSERT INTO "races" VALUES ("203", "Italian Grand Prix", "2017-09-03");
INSERT INTO "races" VALUES ("204", "Spanish Grand Prix", "2019-05-12");
INSERT INTO "results" VALUES ("301", "201", "102", "11", "5");
INSERT INTO "results" VALUES ("302", "202", "101", "12", "3");
INSERT INTO "results" VALUES ("303", "203", "103", "13", "7");
INSERT INTO "results" VALUES ("304", "204", "105", "14", "6");
INSERT INTO "results" VALUES ("305", "201", "104", "15", "4");
INSERT INTO "results" VALUES ("306", "203", "105", "14", "8");
INSERT INTO "results" VALUES ("307", "203", "103", "13", "9");