/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest(平台_业务)\pdm\BCM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_REPORTLIST' AND KSQL_COL_NAME IN ('FCHECKRESULT')) 
 ALTER TABLE T_BCM_REPORTLIST ADD (FCHECKRESULT CHAR(1) DEFAULT '1' NOT NULL );
 EXEC p_AlterColumn 'T_BCM_CHKREPORT', 'FNOTE', 'NVARCHAR(2000)', 'NOT NULL', '1111', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_STRUCTOFACCOUNTP') 
 CREATE TABLE T_BCM_STRUCTOFACCOUNTP (
FID BIGINT DEFAULT 0 NOT NULL,
FISACCOUNTOFFSET CHAR(1) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_STRUCTOFACCOUNT' AND KSQL_COL_NAME IN ('FACCOUNTPART')) 
 ALTER TABLE T_BCM_STRUCTOFACCOUNT ADD (FACCOUNTPART BIGINT DEFAULT 0 NOT NULL );
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_BCM_STRUCTOFACCOUNT', 'FANOTHERNAME', 'NULL', 'NULL', '1001', 'NULL';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SRCDIMBASEDATA' AND KSQL_COL_NAME IN ('FSYSTYPE')) 
 ALTER TABLE T_BCM_SRCDIMBASEDATA ADD (FSYSTYPE INT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SRCDIMMEMBENTRY' AND KSQL_COL_NAME IN ('FPERIODNUMBER')) 
 ALTER TABLE T_BCM_SRCDIMMEMBENTRY ADD (FPERIODNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_SRCDIMMEMBENTRY' AND KSQL_COL_NAME IN ('FPERIODID')) 
 ALTER TABLE T_BCM_SRCDIMMEMBENTRY ADD (FPERIODID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BCM_TEMPLATE' AND KSQL_COL_NAME IN ('FEFFECTIVEDATE')) 
 ALTER TABLE T_BCM_TEMPLATE ADD (FEFFECTIVEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_DATETYPETODIM') 
 CREATE TABLE T_BCM_DATETYPETODIM (
FID BIGINT DEFAULT 0 NOT NULL,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FDATETYPEID BIGINT DEFAULT 0 NOT NULL,
FOTHERDIMENSIONID BIGINT DEFAULT 0 NOT NULL
);


 EXEC p_AlterColumn 'T_BCM_CHECKTMPLASSIGN', 'FTEXTNAME', 'NVARCHAR(100)', 'NOT NULL', '0100', ''' ''';

 EXEC p_AlterColumn 'T_BCM_STRUCTOFCURRENCY', 'FSCALE', 'INT', 'NOT NULL', '0001', '-1';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_MEMBOFDATASORT') 
 CREATE TABLE T_BCM_MEMBOFDATASORT (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER 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_MEMBOFDATASORT_L') 
 CREATE TABLE T_BCM_MEMBOFDATASORT_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_SPCONFIG') 
 CREATE TABLE T_BCM_SPCONFIG (
ID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FSCENARIOID BIGINT DEFAULT 0 NOT NULL,
FPERIODID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_STRUCTOFDATASORT') 
 CREATE TABLE T_BCM_STRUCTOFDATASORT (
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,
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,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSHAREALL 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,
FISSYSMEMBER INT DEFAULT 0 NOT NULL,
FCOPYFROM BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_STRUCTOFDATASORT_L') 
 CREATE TABLE T_BCM_STRUCTOFDATASORT_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(50) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


 --- drop TABLE --------- 请认真检查该脚本 ------------------- 
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_PERIODSRCDIM') 
 DROP TABLE T_BCM_PERIODSRCDIM;

 --- drop TABLE --------- 请认真检查该脚本 ------------------- 
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_PERIODSRCDIM_L') 
 DROP TABLE T_BCM_PERIODSRCDIM_L;

 --- drop TABLE --------- 请认真检查该脚本 ------------------- 
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_YEARSRCDIM') 
 DROP TABLE T_BCM_YEARSRCDIM;

 --- drop TABLE --------- 请认真检查该脚本 ------------------- 
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_YEARSRCDIM_L') 
 DROP TABLE T_BCM_YEARSRCDIM_L;

 --- drop TABLE --------- 请认真检查该脚本 ------------------- 
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_ACCOUNTINGENTITY') 
 DROP TABLE T_BCM_ACCOUNTINGENTITY;

 --- drop TABLE --------- 请认真检查该脚本 ------------------- 
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BCM_ACCOUNTINGENTITY_L') 
 DROP TABLE T_BCM_ACCOUNTINGENTITY_L;


/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest(平台_业务)\pdm\BCM_table.sql **/
