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 "Documents" (
"Document_ID" INT,
"Template_ID" INT,
PRIMARY KEY ("Document_ID"),
FOREIGN KEY ("Template_ID") REFERENCES "Templates"("Template_ID")
);

CREATE TABLE "Ref_Template_Types" (
"Template_Type_Code" CHAR(15),
"Template_Type_Description" VARCHAR(255),
PRIMARY KEY ("Template_Type_Code")
);

CREATE TABLE "Templates" (
"Template_ID" INT UNIQUE,
"Template_Type_Code" CHAR(15),
PRIMARY KEY ("Template_ID"),
FOREIGN KEY ("Template_Type_Code") REFERENCES "Ref_Template_Types"("Template_Type_Code")
);





INSERT INTO "Ref_Template_Types" VALUES ("TYPE_A", "Invoice");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_B", "Receipt");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_C", "Contract");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_D", "Report");
INSERT INTO "Ref_Template_Types" VALUES ("TYPE_E", "Memo");
INSERT INTO "Templates" VALUES ("101", "TYPE_A");
INSERT INTO "Templates" VALUES ("102", "TYPE_B");
INSERT INTO "Templates" VALUES ("103", "TYPE_C");
INSERT INTO "Templates" VALUES ("104", "TYPE_D");
INSERT INTO "Templates" VALUES ("105", "TYPE_E");
INSERT INTO "Templates" VALUES ("106", "TYPE_A");
INSERT INTO "Templates" VALUES ("107", "TYPE_B");
INSERT INTO "Documents" VALUES ("1", "101");
INSERT INTO "Documents" VALUES ("2", "102");
INSERT INTO "Documents" VALUES ("3", "103");
INSERT INTO "Documents" VALUES ("4", "101");
INSERT INTO "Documents" VALUES ("5", "104");
INSERT INTO "Documents" VALUES ("6", "105");
INSERT INTO "Documents" VALUES ("7", "106");
INSERT INTO "Documents" VALUES ("8", "107");
INSERT INTO "Documents" VALUES ("9", "103");
INSERT INTO "Documents" VALUES ("10", "104");
INSERT INTO "Documents" VALUES ("11", "105");
INSERT INTO "Documents" VALUES ("12", "107");
INSERT INTO "Documents" VALUES ("13", "107");
INSERT INTO "Documents" VALUES ("14", "101");
INSERT INTO "Documents" VALUES ("15", "102");