{"Roles": {"columns": [[0, "role_code", "VARCHAR(15)", 0, null, 1], [1, "role_description", "VARCHAR(80)", 0, null, 0]], "primary_keys": ["role_code"], "foreign_keys": [], "unique_constraints": [[[0, 0, "role_code"]]], "check_constraints": []}, "Users": {"columns": [[0, "user_id", "INTEGER", 0, null, 1], [1, "role_code", "VARCHAR(15)", 1, null, 0], [2, "user_name", "VARCHAR(40)", 0, null, 0], [3, "user_login", "VARCHAR(40)", 0, null, 0], [4, "password", "VARCHAR(40)", 0, null, 0]], "primary_keys": ["user_id"], "foreign_keys": [[0, 0, "Roles", "role_code", "role_code", "NO ACTION", "NO ACTION", "NONE"]], "unique_constraints": [], "check_constraints": []}, "Document_Structures": {"columns": [[0, "document_structure_code", "VARCHAR(15)", 0, null, 1], [1, "parent_document_structure_code", "VARCHAR(15)", 0, null, 0], [2, "document_structure_description", "VARCHAR(80)", 0, null, 0]], "primary_keys": ["document_structure_code"], "foreign_keys": [], "unique_constraints": [[[0, 0, "document_structure_code"]]], "check_constraints": []}, "Functional_Areas": {"columns": [[0, "functional_area_code", "VARCHAR(15)", 0, null, 1], [1, "parent_functional_area_code", "VARCHAR(15)", 0, null, 0], [2, "functional_area_description", "VARCHAR(80)", 1, null, 0]], "primary_keys": ["functional_area_code"], "foreign_keys": [], "unique_constraints": [[[0, 0, "functional_area_code"]]], "check_constraints": []}, "Images": {"columns": [[0, "image_id", "INTEGER", 0, null, 1], [1, "image_alt_text", "VARCHAR(80)", 0, null, 0], [2, "image_name", "VARCHAR(40)", 0, null, 0], [3, "image_url", "VARCHAR(255)", 0, null, 0]], "primary_keys": ["image_id"], "foreign_keys": [], "unique_constraints": [], "check_constraints": []}, "Documents": {"columns": [[0, "document_code", "VARCHAR(15)", 0, null, 1], [1, "document_structure_code", "VARCHAR(15)", 1, null, 0], [2, "document_type_code", "VARCHAR(15)", 1, null, 0], [3, "access_count", "INTEGER", 0, null, 0], [4, "document_name", "VARCHAR(80)", 0, null, 0]], "primary_keys": ["document_code"], "foreign_keys": [[0, 0, "Document_Structures", "document_structure_code", "document_structure_code", "NO ACTION", "NO ACTION", "NONE"]], "unique_constraints": [[[0, 0, "document_code"]]], "check_constraints": []}, "Document_Functional_Areas": {"columns": [[0, "document_code", "VARCHAR(15)", 1, null, 0], [1, "functional_area_code", "VARCHAR(15)", 1, null, 0]], "primary_keys": [], "foreign_keys": [[0, 0, "Functional_Areas", "functional_area_code", "functional_area_code", "NO ACTION", "NO ACTION", "NONE"], [1, 0, "Documents", "document_code", "document_code", "NO ACTION", "NO ACTION", "NONE"]], "unique_constraints": [], "check_constraints": []}, "Document_Sections": {"columns": [[0, "section_id", "INTEGER", 0, null, 1], [1, "document_code", "VARCHAR(15)", 1, null, 0], [2, "section_sequence", "INTEGER", 0, null, 0], [3, "section_code", "VARCHAR(20)", 0, null, 0], [4, "section_title", "VARCHAR(80)", 0, null, 0]], "primary_keys": ["section_id"], "foreign_keys": [[0, 0, "Documents", "document_code", "document_code", "NO ACTION", "NO ACTION", "NONE"]], "unique_constraints": [], "check_constraints": []}, "Document_Sections_Images": {"columns": [[0, "section_id", "INTEGER", 1, null, 1], [1, "image_id", "INTEGER", 1, null, 2]], "primary_keys": ["section_id", "image_id"], "foreign_keys": [[0, 0, "Images", "image_id", "image_id", "NO ACTION", "NO ACTION", "NONE"], [1, 0, "Document_Sections", "section_id", "section_id", "NO ACTION", "NO ACTION", "NONE"]], "unique_constraints": [[[0, 0, "section_id"], [1, 1, "image_id"]]], "check_constraints": []}}
CREATE TABLE Roles (
    role_code VARCHAR(15)   PRIMARY KEY,
    role_description VARCHAR(80),
    UNIQUE (role_code)
);

CREATE TABLE Users (
    user_id INTEGER   PRIMARY KEY,
    role_code VARCHAR(15) NOT NULL,
    user_name VARCHAR(40),
    user_login VARCHAR(40),
    password VARCHAR(40),
    FOREIGN KEY (role_code) REFERENCES Roles(role_code)
);

CREATE TABLE Document_Structures (
    document_structure_code VARCHAR(15)   PRIMARY KEY,
    parent_document_structure_code VARCHAR(15),
    document_structure_description VARCHAR(80),
    UNIQUE (document_structure_code)
);

CREATE TABLE Functional_Areas (
    functional_area_code VARCHAR(15)   PRIMARY KEY,
    parent_functional_area_code VARCHAR(15),
    functional_area_description VARCHAR(80) NOT NULL,
    UNIQUE (functional_area_code)
);

CREATE TABLE Images (
    image_id INTEGER   PRIMARY KEY,
    image_alt_text VARCHAR(80),
    image_name VARCHAR(40),
    image_url VARCHAR(255)
);

CREATE TABLE Documents (
    document_code VARCHAR(15)   PRIMARY KEY,
    document_structure_code VARCHAR(15) NOT NULL,
    document_type_code VARCHAR(15) NOT NULL,
    access_count INTEGER,
    document_name VARCHAR(80),
    UNIQUE (document_code),
    FOREIGN KEY (document_structure_code) REFERENCES Document_Structures(document_structure_code)
);

CREATE TABLE Document_Functional_Areas (
    document_code VARCHAR(15) NOT NULL,
    functional_area_code VARCHAR(15) NOT NULL,
    FOREIGN KEY (functional_area_code) REFERENCES Functional_Areas(functional_area_code),
    FOREIGN KEY (document_code) REFERENCES Documents(document_code)
);

CREATE TABLE Document_Sections (
    section_id INTEGER   PRIMARY KEY,
    document_code VARCHAR(15) NOT NULL,
    section_sequence INTEGER,
    section_code VARCHAR(20),
    section_title VARCHAR(80),
    FOREIGN KEY (document_code) REFERENCES Documents(document_code)
);

CREATE TABLE Document_Sections_Images (
    section_id INTEGER NOT NULL  PRIMARY KEY,
    image_id INTEGER NOT NULL  PRIMARY KEY,
    PRIMARY KEY (section_id, image_id),
    UNIQUE (section_id, image_id),
    FOREIGN KEY (image_id) REFERENCES Images(image_id),
    FOREIGN KEY (section_id) REFERENCES Document_Sections(section_id)
);