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 UNIQUE,
"Version_Number" 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 ("PRES", "Presentation");
INSERT INTO "Ref_Template_Types" VALUES ("RPT", "Report");
INSERT INTO "Ref_Template_Types" VALUES ("LTR", "Letter");
INSERT INTO "Ref_Template_Types" VALUES ("INV", "Invoice");
INSERT INTO "Ref_Template_Types" VALUES ("MEMO", "Memorandum");
INSERT INTO "Templates" VALUES ("101", "1", "PRES", "Quarterly Sales Presentation");
INSERT INTO "Templates" VALUES ("102", "2", "RPT", "Annual Financial Report");
INSERT INTO "Templates" VALUES ("103", "1", "LTR", "Client Welcome Letter");
INSERT INTO "Templates" VALUES ("104", "1", "PRES", "Project Proposal Presentation");
INSERT INTO "Templates" VALUES ("105", "3", "RPT", "Monthly Activity Report");
INSERT INTO "Templates" VALUES ("106", "1", "INV", "Service Invoice Template");
INSERT INTO "Templates" VALUES ("107", "1", "MEMO", "Internal Meeting Memo");
INSERT INTO "Templates" VALUES ("108", "2", "PRES", "New Product Launch Presentation");
INSERT INTO "Templates" VALUES ("109", "1", "RPT", "Market Research Report");
INSERT INTO "Templates" VALUES ("110", "1", "PRES", "Investor Briefing Presentation");
INSERT INTO "Documents" VALUES ("1", "101");
INSERT INTO "Documents" VALUES ("2", "102");
INSERT INTO "Documents" VALUES ("3", "103");
INSERT INTO "Documents" VALUES ("4", "104");
INSERT INTO "Documents" VALUES ("5", "105");
INSERT INTO "Documents" VALUES ("6", "101");
INSERT INTO "Documents" VALUES ("7", "108");
INSERT INTO "Documents" VALUES ("8", "106");
INSERT INTO "Documents" VALUES ("9", "107");
INSERT INTO "Documents" VALUES ("10", "110");