SELECT count(DISTINCT template_id) FROM Documents
Count the number of different templates used for documents.
CREATE TABLE Ref_Template_Types (
Template_Type_Code CHAR(15) NOT NULL,
Template_Type_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Template_Type_Code)
);
CREATE TABLE Templates (
Template_ID INTEGER NOT NULL,
Version_Number INTEGER NOT NULL,
Template_Type_Code CHAR(15) NOT NULL,
Date_Effective_From DATETIME,
Date_Effective_To DATETIME,
Template_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Template_ID),
FOREIGN KEY (Template_Type_Code) REFERENCES Ref_Template_Types (Template_Type_Code)
);
CREATE TABLE Documents (
Document_ID INTEGER NOT NULL,
Template_ID INTEGER,
Document_Name VARCHAR(255),
Document_Description VARCHAR(255),
Other_Details VARCHAR(255),
PRIMARY KEY (Document_ID),
FOREIGN KEY (Template_ID) REFERENCES Templates (Template_ID)
);
CREATE TABLE Paragraphs (
Paragraph_ID INTEGER NOT NULL,
Document_ID INTEGER NOT NULL,
Paragraph_Text VARCHAR(255),
Other_Details VARCHAR(255),
PRIMARY KEY (Paragraph_ID),
FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID)
);
INSERT INTO Ref_Template_Types (`Template_Type_Code`, `Template_Type_Description`) VALUES ('PPT', 'Presentation');
INSERT INTO Templates (`Template_ID`, `Version_Number`, `Template_Type_Code`, `Date_Effective_From`, `Date_Effective_To`, `Template_Details`) VALUES (0, 5, 'PP', '2005-11-12 07:09:48', '2008-01-05 14:19:28', '');
INSERT INTO Documents (`Document_ID`, `Template_ID`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (0, 7, 'Introduction of OS', 'n', NULL);
INSERT INTO Paragraphs (`Paragraph_ID`, `Document_ID`, `Paragraph_Text`, `Other_Details`) VALUES (7, 2394, 'Korea', NULL);