/**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_DIMENSIONVIEW') 
CREATE TABLE T_EB_DIMENSIONVIEW (
FID                  BIGINT               NOT NULL DEFAULT 0,
FNUMBER              NVARCHAR(50)         NOT NULL DEFAULT ' ',
FNAME                NVARCHAR(50)         NOT NULL DEFAULT ' ',
FMODELID             BIGINT               NOT NULL DEFAULT 0,
FDESCRIPTION         NVARCHAR(1000)       NOT NULL DEFAULT ' ',
FCREATORID           BIGINT               NOT NULL DEFAULT 0,
FMODIFIERID          BIGINT               NOT NULL DEFAULT 0,
FCREATETIME          DATETIME             NULL,
FMODIFYTIME          DATETIME             NULL,
FDIMENSIONID         BIGINT               NOT NULL DEFAULT 0,
FLEVEL               INT                  NOT NULL DEFAULT 0,
FDSEQ                INT                  NOT NULL DEFAULT 0,
FLONGNUMBER          NVARCHAR(2000)       NOT NULL DEFAULT ' ',
FISLEAF              CHAR(1)              NOT NULL DEFAULT '1',
FSOURCE              CHAR(1) 			 NOT NULL DEFAULT '0',
FPARENTID            BIGINT               NOT NULL DEFAULT 0,
FUSAGE				NVARCHAR(50) 		 NOT NULL DEFAULT ' ',
FBASEVIEWID          BIGINT               NOT NULL DEFAULT 0
);

EXEC P_ALTERPK 'PK_EB_DIMENSIONVIEW', 'T_EB_DIMENSIONVIEW', 'FID', '1';

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

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_VIEWMEMBER_P2') CREATE INDEX IDX_EB_VIEWMEMBER_P2 ON T_EB_VIEWMEMBER ( FDIMENSIONID );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_VIEWMEMBER_P3') CREATE INDEX IDX_EB_VIEWMEMBER_P3 ON T_EB_VIEWMEMBER ( FVIEWID );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_STRUCTOFMETRIC' AND KSQL_COL_NAME IN ('FUSE')) 
 ALTER TABLE T_EB_STRUCTOFMETRIC ADD (FUSE CHAR(1) DEFAULT ' ' NOT NULL );
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_STRUCTOFMETRIC' AND KSQL_COL_NAME IN ('FCOMPAREMETRIC')) 
 ALTER TABLE T_EB_STRUCTOFMETRIC ADD (FCOMPAREMETRIC NVARCHAR(30) DEFAULT ' ' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_PERIODVARIABLE' AND KSQL_COL_NAME IN ('FDESCRIPTION')) 
 ALTER TABLE T_EB_PERIODVARIABLE ADD (FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL );




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