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

CREATE TABLE "races" (
"raceId" INT,
"year" INT,
"circuitId" INT,
"name" TEXT,
"date" DATE,
"time" TEXT,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

CREATE TABLE "results" (
"resultId" INT,
"position" INT,
PRIMARY KEY ("resultId")
);



INSERT INTO "circuits" VALUES ("1", "Yas Marina Circuit", "Abu Dhabi");
INSERT INTO "circuits" VALUES ("2", "Circuit de Monaco", "Monte Carlo");
INSERT INTO "circuits" VALUES ("3", "Silverstone Circuit", "Silverstone");
INSERT INTO "circuits" VALUES ("4", "Autodromo Nazionale Monza", "Monza");
INSERT INTO "circuits" VALUES ("5", "Circuit de Spa-Francorchamps", "Spa");
INSERT INTO "races" VALUES ("1", "2010", "1", "Abu Dhabi Grand Prix", "2010-11-14", "17:00:00");
INSERT INTO "races" VALUES ("2", "2011", "1", "Abu Dhabi Grand Prix", "2011-11-13", "17:00:00");
INSERT INTO "races" VALUES ("3", "2010", "2", "Monaco Grand Prix", "2010-05-16", "14:00:00");
INSERT INTO "races" VALUES ("4", "2012", "1", "Abu Dhabi Grand Prix", "2012-11-04", "17:00:00");
INSERT INTO "races" VALUES ("5", "2013", "1", "Abu Dhabi Grand Prix", "2013-11-03", "17:00:00");
INSERT INTO "races" VALUES ("6", "2014", "1", "Abu Dhabi Grand Prix", "2014-11-23", "17:00:00");
INSERT INTO "races" VALUES ("7", "2015", "1", "Abu Dhabi Grand Prix", "2015-11-29", "17:00:00");
INSERT INTO "races" VALUES ("8", "2016", "1", "Abu Dhabi Grand Prix", "2016-11-27", "17:00:00");
INSERT INTO "races" VALUES ("9", "2017", "1", "Abu Dhabi Grand Prix", "2017-11-26", "17:00:00");
INSERT INTO "races" VALUES ("10", "2018", "1", "Abu Dhabi Grand Prix", "2018-11-25", "17:00:00");
INSERT INTO "races" VALUES ("11", "2019", "1", "Abu Dhabi Grand Prix", "2019-12-01", "17:00:00");
INSERT INTO "races" VALUES ("12", "2009", "1", "Abu Dhabi Grand Prix", "2009-11-01", "17:00:00");
INSERT INTO "races" VALUES ("13", "2020", "1", "Abu Dhabi Grand Prix", "2020-12-13", "17:10:00");
INSERT INTO "races" VALUES ("14", "2010", "3", "British Grand Prix", "2010-07-11", "13:00:00");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");
INSERT INTO "results" VALUES ("4", "1");
INSERT INTO "results" VALUES ("5", "2");