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

CREATE TABLE "Paragraphs" (
"Paragraph_ID" INT,
"Paragraph_Text" VARCHAR(255),
PRIMARY KEY ("Paragraph_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,
"Version_Number" INT,
"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 ("BK", "Book Template");
INSERT INTO "Ref_Template_Types" VALUES ("AR", "Article Template");
INSERT INTO "Ref_Template_Types" VALUES ("RP", "Report Template");
INSERT INTO "Ref_Template_Types" VALUES ("BKX", "Special Book Template");
INSERT INTO "Ref_Template_Types" VALUES ("BK", "Backup Book Template");
INSERT INTO "Templates" VALUES ("1", "1", "BK");
INSERT INTO "Templates" VALUES ("2", "2", "AR");
INSERT INTO "Templates" VALUES ("3", "1", "RP");
INSERT INTO "Templates" VALUES ("4", "3", "BK");
INSERT INTO "Templates" VALUES ("5", "1", "BKX");
INSERT INTO "Templates" VALUES ("6", "2", "BK");
INSERT INTO "Documents" VALUES ("101", "1", "Introduction to Databases");
INSERT INTO "Documents" VALUES ("102", "2", "Modern Art Review");
INSERT INTO "Documents" VALUES ("103", "4", "Advanced Book Writing");
INSERT INTO "Documents" VALUES ("104", "3", "Annual Financial Report");
INSERT INTO "Documents" VALUES ("105", "5", "Special Edition Book");
INSERT INTO "Documents" VALUES ("106", "6", "Backup Book Draft");
INSERT INTO "Documents" VALUES ("107", "1", "Database Systems Overview");
INSERT INTO "Documents" VALUES ("108", "4", "Book Writing Techniques");
INSERT INTO "Documents" VALUES ("109", "2", "Art and Culture");
INSERT INTO "Documents" VALUES ("110", "3", "Quarterly Report");
INSERT INTO "Paragraphs" VALUES ("201", "This paragraph introduces the topic.");
INSERT INTO "Paragraphs" VALUES ("202", "This paragraph explains the methodology.");
INSERT INTO "Paragraphs" VALUES ("203", "This paragraph summarizes the findings.");
INSERT INTO "Paragraphs" VALUES ("204", "This paragraph provides background information.");
INSERT INTO "Paragraphs" VALUES ("205", "This paragraph discusses related work.");
INSERT INTO "Paragraphs" VALUES ("206", "This paragraph concludes the document.");
INSERT INTO "Paragraphs" VALUES ("207", "This paragraph contains references.");
INSERT INTO "Paragraphs" VALUES ("208", "This paragraph outlines the structure.");
INSERT INTO "Paragraphs" VALUES ("209", "This paragraph highlights key points.");
INSERT INTO "Paragraphs" VALUES ("210", "This paragraph describes the data.");