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 "Paragraphs" (
"Paragraph_ID" INT,
"Document_ID" INT,
PRIMARY KEY ("Paragraph_ID"),
FOREIGN KEY ("Document_ID") REFERENCES "Documents"("Document_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,
"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 ("Presentation", "Presentation");
INSERT INTO "Ref_Template_Types" VALUES ("REPORT", "Report");
INSERT INTO "Ref_Template_Types" VALUES ("INVOICE", "Invoice");
INSERT INTO "Ref_Template_Types" VALUES ("MEMO", "Memorandum");
INSERT INTO "Ref_Template_Types" VALUES ("LETTER", "Letter");
INSERT INTO "Templates" VALUES ("101", "Presentation", "Quarterly Business Review Slides");
INSERT INTO "Templates" VALUES ("102", "REPORT", "Annual Financial Report");
INSERT INTO "Templates" VALUES ("103", "Presentation", "Product Launch Presentation");
INSERT INTO "Templates" VALUES ("104", "INVOICE", "Standard Customer Invoice");
INSERT INTO "Templates" VALUES ("105", "MEMO", "Internal Staff Memo");
INSERT INTO "Templates" VALUES ("106", "Presentation", "Sales Strategy Presentation");
INSERT INTO "Templates" VALUES ("107", "LETTER", "Customer Thank You Letter");
INSERT INTO "Documents" VALUES ("201", "101");
INSERT INTO "Documents" VALUES ("202", "102");
INSERT INTO "Documents" VALUES ("203", "103");
INSERT INTO "Documents" VALUES ("204", "104");
INSERT INTO "Documents" VALUES ("205", "105");
INSERT INTO "Documents" VALUES ("206", "106");
INSERT INTO "Documents" VALUES ("207", "107");
INSERT INTO "Paragraphs" VALUES ("301", "201");
INSERT INTO "Paragraphs" VALUES ("302", "201");
INSERT INTO "Paragraphs" VALUES ("303", "202");
INSERT INTO "Paragraphs" VALUES ("304", "203");
INSERT INTO "Paragraphs" VALUES ("305", "203");
INSERT INTO "Paragraphs" VALUES ("306", "206");
INSERT INTO "Paragraphs" VALUES ("307", "206");
INSERT INTO "Paragraphs" VALUES ("308", "207");