CREATE TABLE ZH_TABLE_TRL (
  ID           NUMBER        NOT NULL,
  TABLE_NAME   VARCHAR2(500) NOT NULL,
  TABLE_COLUMN VARCHAR2(500) NOT NULL,
  IS_ACTIVE    VARCHAR2(1)   DEFAULT 'Y' NOT NULL,
  CREATED      DATE          NOT NULL,
  CREATED_BY   VARCHAR2(255) NOT NULL,
  UPDATED      DATE          NOT NULL,
  UPDATED_BY   VARCHAR2(255) NOT NULL,
  ORGANIZATION_ID NUMBER     NOT NULL,
  NRORG             NUMBER 	        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
  IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
  DTINCLUSAO        DATE            DEFAULT SYSDATE,
  DTULTATU          DATE            DEFAULT SYSDATE,
  NRORGINCLUSAO     NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
  CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 					NULL,
  NRORGULTATU       NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
  CDOPERULTATU      VARCHAR2(12)    DEFAULT '1',
	CONSTRAINT CKC_IDATIVO_ZH_TABLE_TRL CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT ZH_TABLE_TRL_PK         PRIMARY KEY (ID),
    CONSTRAINT CKC_IS_ACTIVE_TABLE_TRL CHECK (IS_ACTIVE IN ('Y', 'N'))
)
/

CREATE SEQUENCE SEQ_ZH_TABLE_TRL_ID START WITH 1 MINVALUE 1 INCREMENT BY 1
/

CREATE TABLE ZH_TABLE_TRL_LANGUAGE (
  ID           NUMBER        NOT NULL,
  TABLE_TRL_ID NUMBER        NOT NULL,
  LANGUAGE_ID  NUMBER        NOT NULL,
  IS_ACTIVE    VARCHAR2(1)   DEFAULT 'Y' NOT NULL,
  CREATED      DATE          NOT NULL,
  CREATED_BY   VARCHAR2(255) NOT NULL,
  UPDATED      DATE          NOT NULL,
  UPDATED_BY   VARCHAR2(255) NOT NULL,
  ORGANIZATION_ID NUMBER     NOT NULL,
  NRORG             NUMBER 	        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
  IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
  DTINCLUSAO        DATE            DEFAULT SYSDATE,
  DTULTATU          DATE            DEFAULT SYSDATE,
  NRORGINCLUSAO     NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
  CDOPERINCLUSAO    VARCHAR2(12)    DEFAULT '1' 					NULL,
  NRORGULTATU       NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
  CDOPERULTATU      VARCHAR2(12)    DEFAULT '1',
    CONSTRAINT CKC_IDATIVO_ZH_TABLE_TRL_LANG CHECK (IDATIVO IN ('S','N')),
    CONSTRAINT ZH_TABLE_TRL_LANGUAGE_PK  PRIMARY KEY (ID),
    CONSTRAINT CKC_IS_ACTIVE_TAB_TRL_LAN CHECK (IS_ACTIVE IN ('Y', 'N')),
    CONSTRAINT TAB_TRL_LAN_TABLE_FK      FOREIGN KEY (TABLE_TRL_ID) REFERENCES ZH_TABLE_TRL (ID),
    CONSTRAINT TAB_TRL_LAN_LANGUAGE_FK   FOREIGN KEY (LANGUAGE_ID)  REFERENCES ZH_LANGUAGE (ID)
)
/
CREATE INDEX FK_TAB_TRL_LAN_TABLE ON ZH_TABLE_TRL_LANGUAGE(TABLE_TRL_ID ASC)
/

CREATE INDEX FK_TAB_TRL_LAN_LANGUAGE ON ZH_TABLE_TRL_LANGUAGE(LANGUAGE_ID ASC)
/

CREATE SEQUENCE SEQ_ZH_TABLE_TRL_LANGUAGE_ID START WITH 1 MINVALUE 1 INCREMENT BY 1
/

ALTER TABLE ZH_WORDS ADD TABLE_TRL_ID NUMBER
/

ALTER TABLE ZH_WORDS ADD CONSTRAINT WORDS_TABLE_TRL_FK FOREIGN KEY (TABLE_TRL_ID) REFERENCES ZH_TABLE_TRL (ID)
/

CREATE INDEX FK_WORDS_TABLE_TRL ON ZH_WORDS(TABLE_TRL_ID ASC)
/

ALTER TABLE ZH_WORDS_TRL ADD TABLE_KEY VARCHAR2(500)
/