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", "mclaren", "McLaren", "https://www.mclaren.com");
INSERT INTO "constructors" VALUES ("2", "ferrari", "Ferrari", "https://www.ferrari.com");
INSERT INTO "constructors" VALUES ("3", "redbull", "Red Bull Racing", "https://www.redbullracing.com");
INSERT INTO "constructors" VALUES ("4", "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", "Belgian Grand Prix", "2009-08-30");
INSERT INTO "results" VALUES ("1001", "101", "44", "4", "1", "1:56.345");
INSERT INTO "results" VALUES ("1002", "101", "22", "1", "2", "1:57.123");
INSERT INTO "results" VALUES ("1003", "101", "5", "3", "3", "1:58.456");
INSERT INTO "results" VALUES ("1004", "102", "44", "4", "1", "1:40.789");
INSERT INTO "results" VALUES ("1005", "102", "22", "1", "2", "1:41.234");
INSERT INTO "results" VALUES ("1006", "103", "5", "3", "1", "1:45.678");
INSERT INTO "results" VALUES ("1007", "103", "44", "4", "2", "1:46.123");