/**Begin D:\PDM_UPGRADE\PDM1\EB_constraint.sql **/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_CONTROLRULEGROUPDIM') 
CREATE TABLE T_EB_CONTROLRULEGROUPDIM (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FGROUPDIM BIGINT NULL,
FISOBODIM CHAR(1) DEFAULT '0' NOT NULL,
FOBODIMINDEX BIGINT NULL
);

EXEC P_ALTERPK 'PK_EB_CONTROLRULEGROUPDIM', 'T_EB_CONTROLRULEGROUPDIM', 'FENTRYID', '1';

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



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_CONTROLRULEOBORANGE') 
CREATE TABLE T_EB_CONTROLRULEOBORANGE (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FOBOMEMBER BIGINT NULL,
FMEMRANGE NVARCHAR(50) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_EB_CONTROLRULEOBORANGE', 'T_EB_CONTROLRULEOBORANGE', 'FENTRYID', '1';

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



IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CONTROLRULEDEFINEDS' AND KSQL_COL_NAME IN ('FGROUPACCOUNT')) 
ALTER TABLE T_EB_CONTROLRULEDEFINEDS ADD (FGROUPACCOUNT BIGINT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CONTROLRULEMAIN' AND KSQL_COL_NAME IN ('FSHOWGROUPDIM')) 
ALTER TABLE T_EB_CONTROLRULEMAIN ADD (FSHOWGROUPDIM NVARCHAR(50) DEFAULT ' ' NOT NULL);

/**End D:\PDM_UPGRADE\PDM1\EB_constraint.sql **/