/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\EB_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_ACCOUNTRULEFORMULA' AND KSQL_COL_NAME IN ('FMODELID')) 
 ALTER TABLE T_EB_ACCOUNTRULEFORMULA ADD (FMODELID BIGINT DEFAULT 0 NOT NULL );
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_TASKPROCESS') 
 CREATE TABLE T_EB_TASKPROCESS (
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FTASKID              BIGINT               NOT NULL DEFAULT 0,
   FORGID               BIGINT               NOT NULL DEFAULT 0,
   FTEMPLATEID          BIGINT               NOT NULL DEFAULT 0,
   FEXECUTORID          BIGINT               NOT NULL DEFAULT 0,
   FSTATE               CHAR(1)              NOT NULL DEFAULT '0',
   FCREATER             BIGINT               NOT NULL DEFAULT 0,
   FCREATEDATE          DATETIME             ,
   FMODIFIER            BIGINT               NOT NULL DEFAULT 0,
   FMODIFYDATE          DATETIME
);

 /*EXEC P_ALTERPK 'PK_T_EB_TASKPROCESS', 'T_EB_TaskProcess', 'FID', '1'; */

/*==============================================================*/
/* Index: IX_EB_TaskProcess                                     */
/*==============================================================*/
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_EB_TaskProcess')
CREATE INDEX IX_EB_TASKPROCESS ON T_EB_TASKPROCESS (
FTASKID ASC,
FTEMPLATEID ASC,
FORGID ASC,
FEXECUTORID ASC
);

 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_CONTROLRULEACCOUNT') 
CREATE TABLE T_EB_CONTROLRULEACCOUNT (
   FENTRYID             BIGINT               NOT NULL DEFAULT 0,
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FACCOUNTID           BIGINT               NOT NULL DEFAULT 0
);
 EXEC P_ALTERPK 'PK_T_EB_CONTROLRULEACCOUNT', 'T_EB_CONTROLRULEACCOUNT', 'FENTRYID', '1';

/*==============================================================*/
/* INDEX: IDX_EB_CONTROLRULEACCOUNT                             */
/*==============================================================*/
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_CONTROLRULEACCOUNT')
CREATE INDEX IDX_EB_CONTROLRULEACCOUNT ON T_EB_CONTROLRULEACCOUNT (
FACCOUNTID ASC
);

 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_CONTROLRULEDEFINEDS') 
CREATE TABLE T_EB_CONTROLRULEDEFINEDS (
   FENTRYID             BIGINT               NOT NULL DEFAULT 0,
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FUSERDEFINEDID1      BIGINT               NOT NULL DEFAULT 0,
   FUSERDEFINEDID5      BIGINT               NOT NULL DEFAULT 0,
   FUSERDEFINEDID6      BIGINT               NOT NULL DEFAULT 0,
   FUSERDEFINEDID2      BIGINT               NOT NULL DEFAULT 0,
   FUSERDEFINEDID3      BIGINT               NOT NULL DEFAULT 0,
   FUSERDEFINEDID4      BIGINT               NOT NULL DEFAULT 0,
   FUSERDEFINEDID7      BIGINT               NOT NULL DEFAULT 0
);
 EXEC P_ALTERPK 'PK_T_EB_CONTROLRULEDEFINEDS', 'T_EB_CONTROLRULEDEFINEDS', 'FENTRYID', '1';

/*==============================================================*/
/* INDEX: IDX_EB_CONTROLRULEDEFINEDS                            */
/*==============================================================*/
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_CONTROLRULEDEFINEDS')
CREATE INDEX IDX_EB_CONTROLRULEDEFINEDS ON T_EB_CONTROLRULEDEFINEDS (
FID ASC
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CONTROLRULEMAIN' AND KSQL_COL_NAME IN ('FMODELID')) 
 ALTER TABLE T_EB_CONTROLRULEMAIN ADD (FMODELID BIGINT DEFAULT 0 NOT NULL );
 
 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FGROUPID', 'BIGINT', 'NOT NULL', '0001', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CONTROLRULEMAIN' AND KSQL_COL_NAME IN ('FISDEFAULT')) 
 ALTER TABLE T_EB_CONTROLRULEMAIN ADD (FISDEFAULT CHAR(1) DEFAULT '0' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CONTROLRULEMAIN' AND KSQL_COL_NAME IN ('FMODIFIERFIELD')) 
 ALTER TABLE T_EB_CONTROLRULEMAIN ADD (FMODIFIERFIELD BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CONTROLRULEMAIN' AND KSQL_COL_NAME IN ('FMODIFYDATEFIELD')) 
 ALTER TABLE T_EB_CONTROLRULEMAIN ADD (FMODIFYDATEFIELD DATETIME );
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FSHOWORGRANGE', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FUSERDEFINEDID1', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FUSERDEFINEDID2', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FUSERDEFINEDID3', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FUSERDEFINEDID4', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FUSERDEFINEDID5', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FUSERDEFINEDID6', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FUSERDEFINEDID7', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FSHOWGROUP', 'NULL', 'NULL', '1001', 'NULL';

 EXEC P_ALTERPK 'PK_EB_ControlRuleMain', 'T_EB_CONTROLRULEMAIN', 'FID', '1';
 
  --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_CONTROLRULEMAIN', 'FENTRYID', 'NULL', 'NULL', '1001', 'NULL';
 
 --  IF  EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_CONTROLRULEMAIN_FID')
 --EXEC p_DropIdx 'IDX_EB_CONTROLRULEMAIN_FID', 'T_EB_CONTROLRULEMAIN';

  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ControlRuleMain')
 create index IDX_EB_ControlRuleMain on T_EB_ControlRuleMain (
fmodelid ASC
)
 

/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\EB_table.sql **/
