/**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_PERIODVARIABLE' AND KSQL_COL_NAME IN ('FGROUPTYPE')) 
 ALTER TABLE T_EB_PERIODVARIABLE ADD (FGROUPTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL );
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_PERIODVARIABLE' AND KSQL_COL_NAME IN ('FPARENTID')) 
 ALTER TABLE T_EB_PERIODVARIABLE ADD (FPARENTID NVARCHAR(50) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_RULEVARIABLE') 
CREATE TABLE T_EB_RULEVARIABLE
(
FID      BIGINT                          NOT NULL DEFAULT 0,
FMODELID BIGINT							 NOT NULL DEFAULT 0,
FTYPE    VARCHAR(50) 					 NOT NULL DEFAULT ' ',
CONSTRAINT PK_T_EB_RULEVARIABLE PRIMARY KEY (FID)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_RULEVARIABLE_P1') CREATE INDEX IDX_EB_RULEVARIABLE_P1 ON T_EB_RULEVARIABLE (FMODELID);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_RULEVARIABLEENTITY') 
CREATE TABLE T_EB_RULEVARIABLEENTITY
(
FID               BIGINT                  NOT NULL DEFAULT 0,
FENTRYID          BIGINT                  NOT NULL DEFAULT 0,
FSEQ              INT      				  NOT NULL DEFAULT 0,
FDIMENSION        BIGINT				  NOT NULL DEFAULT 0,
FVARIABLENAME     VARCHAR(50)  			  NOT NULL DEFAULT ' ',
FVARIABLENUMBER   BIGINT				  NOT NULL DEFAULT 0,
FVARIABLE         VARCHAR(50)  			  NOT NULL DEFAULT ' ',
FVARIABLEJSONTEXT VARCHAR(255) 			  NOT NULL DEFAULT ' ',
CONSTRAINT PK_T_EB_RULEVARIABLEENTITY PRIMARY KEY (FENTRYID)
);

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_RULEVARIABLEENTITY_P1') CREATE INDEX IDX_EB_RULEVARIABLEENTITY_P1 ON T_EB_RULEVARIABLEENTITY ( FID );


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