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) UNIQUE,
"Template_Type_Description" VARCHAR(255),
PRIMARY KEY ("Template_Type_Code")
);

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





INSERT INTO "Ref_Template_Types" VALUES ("INV", "Invoice");
INSERT INTO "Ref_Template_Types" VALUES ("ORD", "Order Form");
INSERT INTO "Ref_Template_Types" VALUES ("REP", "Report");
INSERT INTO "Ref_Template_Types" VALUES ("BK", "Book");
INSERT INTO "Ref_Template_Types" VALUES ("MEMO", "Memo");
INSERT INTO "Ref_Template_Types" VALUES ("LTR", "Letter");
INSERT INTO "Ref_Template_Types" VALUES ("PRES", "Presentation");
INSERT INTO "Templates" VALUES ("1", "INV", "Standard Invoice Template");
INSERT INTO "Templates" VALUES ("2", "ORD", "Purchase Order Template");
INSERT INTO "Templates" VALUES ("3", "REP", "Quarterly Sales Report");
INSERT INTO "Templates" VALUES ("4", "BK", "Novel Manuscript Template");
INSERT INTO "Templates" VALUES ("5", "MEMO", "Internal Memo Template");
INSERT INTO "Templates" VALUES ("6", "LTR", "Formal Business Letter");
INSERT INTO "Templates" VALUES ("7", "BK", "Technical Manual Template");
INSERT INTO "Templates" VALUES ("8", "INV", "Detailed Invoice Template");
INSERT INTO "Templates" VALUES ("9", "PRES", "Project Proposal Presentation");
INSERT INTO "Documents" VALUES ("101", "1");
INSERT INTO "Documents" VALUES ("102", "2");
INSERT INTO "Documents" VALUES ("103", "3");
INSERT INTO "Documents" VALUES ("104", "4");
INSERT INTO "Documents" VALUES ("105", "5");
INSERT INTO "Documents" VALUES ("106", "6");
INSERT INTO "Documents" VALUES ("107", "7");
INSERT INTO "Documents" VALUES ("108", "1");
INSERT INTO "Documents" VALUES ("109", "4");
INSERT INTO "Documents" VALUES ("110", "9");