/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\BCM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_SCENEPERIOD') 
 CREATE TABLE T_BCM_SCENEPERIOD (
FID BIGINT DEFAULT 0 NOT NULL,
FPKID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_CHKFORMULASETTING' AND KSQL_COL_NAME IN ('FVFORMULA')) 
 ALTER TABLE T_BCM_CHKFORMULASETTING ADD (FVFORMULA NCLOB );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_CHKFORMULASETTING' AND KSQL_COL_NAME IN ('FCHINESEFORMULA')) 
 ALTER TABLE T_BCM_CHKFORMULASETTING ADD (FCHINESEFORMULA NCLOB );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_CHKREPORT' AND KSQL_COL_NAME IN ('FMAPDIM')) 
 ALTER TABLE T_BCM_CHKREPORT ADD (FMAPDIM VARCHAR(500) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SCHEMECOLLECTLOG' AND KSQL_COL_NAME IN ('FDIMMEMBERS')) 
 ALTER TABLE T_BCM_SCHEMECOLLECTLOG ADD (FDIMMEMBERS VARCHAR(1000) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SCHEMECOLLECTLOG' AND KSQL_COL_NAME IN ('FDATAFROM_TAG')) 
 ALTER TABLE T_BCM_SCHEMECOLLECTLOG ADD (FDATAFROM_TAG NCLOB );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SCHEMECOLLECTLOG' AND KSQL_COL_NAME IN ('FDATAFROM')) 
 ALTER TABLE T_BCM_SCHEMECOLLECTLOG ADD (FDATAFROM NVARCHAR(510) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SCHEMECOLLECTLOG' AND KSQL_COL_NAME IN ('FERROR')) 
 ALTER TABLE T_BCM_SCHEMECOLLECTLOG ADD (FERROR NCLOB );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SCHEMECOLLECTLOG' AND KSQL_COL_NAME IN ('FRESULT')) 
 ALTER TABLE T_BCM_SCHEMECOLLECTLOG ADD (FRESULT VARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SCHEMECOLLECTLOG' AND KSQL_COL_NAME IN ('FEXECUTERECID')) 
 ALTER TABLE T_BCM_SCHEMECOLLECTLOG ADD (FEXECUTERECID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_MEMBOFMYCOMPANY') 
 CREATE TABLE T_BCM_MEMBOFMYCOMPANY (
FID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_MEMBOFMYCOMPANY_L') 
 CREATE TABLE T_BCM_MEMBOFMYCOMPANY_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_STRUCTOFMYCOMPANY') 
 CREATE TABLE T_BCM_STRUCTOFMYCOMPANY (
FID BIGINT DEFAULT 0 NOT NULL,
FLONGNUMBER NVARCHAR(200) DEFAULT ' ' NOT NULL,
FMEMBERID BIGINT DEFAULT 0 NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FISLEAF CHAR(1) DEFAULT ' ' NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSTORAGETYPE CHAR(1) DEFAULT ' ' NOT NULL,
FAGGOPRT CHAR(1) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FISSYSMEMBER INT DEFAULT 0 NOT NULL,
FDPROPERTYID1 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID2 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID3 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID4 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID5 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID6 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID7 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID8 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID9 BIGINT DEFAULT 0 NOT NULL,
FDPROPERTYID10 BIGINT DEFAULT 0 NOT NULL,
FSHAREALL INT DEFAULT 0 NOT NULL,
FCOPYFROM BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FREFERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_STRUCTOFMYCOMPANY_L') 
 CREATE TABLE T_BCM_STRUCTOFMYCOMPANY_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_ENUMVALUE' AND KSQL_COL_NAME IN ('FMASTERID')) 
 ALTER TABLE T_BCM_ENUMVALUE ADD (FMASTERID BIGINT DEFAULT 0 NOT NULL );
 --- drop TABLE --------- 请认真检查该脚本 ------------------- 
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_SPCONFIG') 
 DROP TABLE T_BCM_SPCONFIG;


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