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 "constructors" (
"constructorId" INT UNIQUE,
"constructorRef" TEXT,
"name" TEXT,
"url" TEXT,
PRIMARY KEY ("constructorId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"constructorId" INT,
"position" INT,
"time" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("constructorId") REFERENCES "constructors"("constructorId")
);



INSERT INTO "constructors" VALUES ("1", "ferrari", "Scuderia Ferrari", "https://www.ferrari.com");
INSERT INTO "constructors" VALUES ("2", "mclaren", "McLaren F1 Team", "https://www.mclaren.com");
INSERT INTO "constructors" VALUES ("3", "redbull", "Red Bull Racing", "https://www.redbullracing.com");
INSERT INTO "constructors" VALUES ("4", "renault", "Renault F1 Team", "https://www.renaultsport.com");
INSERT INTO "constructors" VALUES ("5", "brawn", "Brawn GP", "https://www.brawngp.com");
INSERT INTO "races" VALUES ("101", "2009", "Singapore Grand Prix", "2009-09-27");
INSERT INTO "races" VALUES ("102", "2009", "Monaco Grand Prix", "2009-05-24");
INSERT INTO "races" VALUES ("103", "2009", "British Grand Prix", "2009-07-12");
INSERT INTO "races" VALUES ("104", "2010", "Singapore Grand Prix", "2010-09-26");
INSERT INTO "results" VALUES ("1001", "101", "201", "5", "1", "1:56.259");
INSERT INTO "results" VALUES ("1002", "101", "202", "3", "2", "1:56.259");
INSERT INTO "results" VALUES ("1003", "101", "203", "2", "3", "1:57.000");
INSERT INTO "results" VALUES ("1004", "101", "204", "1", "4", "1:58.500");
INSERT INTO "results" VALUES ("1005", "102", "201", "5", "1", "1:39.123");
INSERT INTO "results" VALUES ("1006", "102", "205", "3", "2", "1:39.500");
INSERT INTO "results" VALUES ("1007", "103", "206", "4", "1", "1:30.000");
INSERT INTO "results" VALUES ("1008", "103", "207", "2", "2", "1:30.500");
INSERT INTO "results" VALUES ("1009", "104", "208", "3", "1", "1:55.000");
INSERT INTO "results" VALUES ("1010", "104", "209", "1", "2", "1:55.500");
INSERT INTO "results" VALUES ("1011", "101", "210", "4", "NULL", "NULL");