/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\EB_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_DIMENSIONVARIABLE') 
 CREATE TABLE T_EB_DIMENSIONVARIABLE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FDSEQ INT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT 'A' NOT NULL,
FCREATER BIGINT DEFAULT 0 NOT NULL,
FCREATEDATE DATETIME,
FMODIFIER BIGINT DEFAULT 0 NOT NULL,
FMODIFYDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BIZRULERELATION' AND KSQL_COL_NAME ='FSONRULEMEMBERKEY') 
 ALTER TABLE T_EB_BIZRULERELATION ADD (FSONRULEMEMBERKEY NCLOB );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_ROLLINITRECORDTRIAL') 
 CREATE TABLE T_EB_ROLLINITRECORDTRIAL (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FTRIALID BIGINT DEFAULT 0 NOT NULL,
FSOURCE NVARCHAR(5) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_DIMENSIONVARIABLE_L') 
 CREATE TABLE T_EB_DIMENSIONVARIABLE_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(500) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_PERIODVARIABLE_L') 
 CREATE TABLE T_EB_PERIODVARIABLE_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(500) DEFAULT ' ' NOT NULL
);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_PERIODVARIABLE' AND KSQL_COL_NAME ='FDIMENSIONID') 
 ALTER TABLE T_EB_PERIODVARIABLE ADD (FDIMENSIONID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_PERIODVARIABLE' AND KSQL_COL_NAME ='FMODELID') 
 ALTER TABLE T_EB_PERIODVARIABLE ADD (FMODELID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_USERSELECT' AND KSQL_COL_NAME ='FEBPERIOD') 
 ALTER TABLE T_EB_USERSELECT ADD (FEBPERIOD BIGINT DEFAULT 0 NOT NULL );

 
 
 -- 预算控制维度匹配规则
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_BGCONTROLINDEX') 
CREATE TABLE T_EB_BGCONTROLINDEX (
FENTITYNUMBER NVARCHAR(80) NOT NULL DEFAULT ' ', 
FBIZID NVARCHAR(80) NOT NULL DEFAULT ' ', 
FTABLE NVARCHAR(80) NOT NULL DEFAULT ' '
);

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_EB_BGCONTROLINDEX') 
CREATE INDEX IX_EB_BGCONTROLINDEX ON T_EB_BGCONTROLINDEX ( FENTITYNUMBER, FBIZID, FTABLE );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FUSERDEFINEDDIMID1') 
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FUSERDEFINEDDIMID1 BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FUSERDEFINEDDIMID2') 
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FUSERDEFINEDDIMID2 BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FUSERDEFINEDDIMID3') 
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FUSERDEFINEDDIMID3 BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FUSERDEFINEDDIMID4') 
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FUSERDEFINEDDIMID4 BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FUSERDEFINEDDIMID5') 
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FUSERDEFINEDDIMID5 BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DIMMATERULEBILL' AND KSQL_COL_NAME ='FUSERDEFINEDDIMID6') 
 ALTER TABLE T_EB_DIMMATERULEBILL ADD (FUSERDEFINEDDIMID6 BIGINT DEFAULT 0 NOT NULL );
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_STRUCTOFCHANGETYPE' AND KSQL_COL_NAME ='FDATATYPE') 
 ALTER TABLE T_EB_STRUCTOFCHANGETYPE ADD (FDATATYPE NVARCHAR(50) DEFAULT ' ' NOT NULL );

 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALIZED_RANGE' AND KSQL_COL_NAME ='FENTITYRANGENUMBERS') 
 ALTER TABLE T_EB_CENTRALIZED_RANGE ADD (FENTITYRANGENUMBERS NCLOB );
/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\EB_table.sql **/
