/**Begin D:\k3Cloud\PDM_UPGRADE\PDM1\MDS_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FPLANID') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FPLANID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FMRTYPE') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FMRTYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FCHECKTYPE') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FCHECKTYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FCABINCONFIG') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FCABINCONFIG BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FSCHDSTATUS') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FSCHDSTATUS BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FCONSTRUCTIONUNIT') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FCONSTRUCTIONUNIT BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FREPAIRCYCLESPLIT') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FREPAIRCYCLESPLIT VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FWORKREPAIRCYCLE') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FWORKREPAIRCYCLE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FSOURCEBILLTYPE') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FSOURCEBILLTYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FPLANCODE') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FPLANCODE NVARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FOVERDEVICE') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FOVERDEVICE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FPOLARISSTATUS') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FPOLARISSTATUS BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FWORKCENTER') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FWORKCENTER BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FPREAPPROACHTIME') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FPREAPPROACHTIME DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_STOCKUPSTATUS' AND KSQL_COL_NAME ='FPREDEPARTTIME') 
 ALTER TABLE T_MDS_STOCKUPSTATUS ADD (FPREDEPARTTIME DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_ADJUSTRECORD') 
 CREATE TABLE T_MDS_ADJUSTRECORD (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FADJUSTREASON NVARCHAR(500) DEFAULT ' ' NOT NULL,
FBEFOREADJSTUS BIGINT DEFAULT 0 NOT NULL,
FAFTERADJSTUS BIGINT DEFAULT 0 NOT NULL,
FPLANID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FFIELD VARCHAR(50) DEFAULT ' ' NOT NULL,
FISSYSTEM CHAR(1) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_POLARISSTATUS') 
 CREATE TABLE T_MDS_POLARISSTATUS (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCTRLSTRATEGY VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEDATAID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBITINDEX BIGINT DEFAULT 0 NOT NULL,
FBITINDEX BIGINT DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_POLARISSTATUS_L') 
 CREATE TABLE T_MDS_POLARISSTATUS_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_RULESET_RANGE') 
 CREATE TABLE T_MDS_RULESET_RANGE (
FPKID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_RULESETENTITY') 
 CREATE TABLE T_MDS_RULESETENTITY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSTOCKSTATUS BIGINT DEFAULT 0 NOT NULL,
FMATCHELEMENT NVARCHAR(255) DEFAULT ' ' NOT NULL,
FFILTERCONDITION NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FFILTERCONDITIONVAL NCLOB,
FALLOWADJUST CHAR(1) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_STOCKSTATUSRULE') 
 CREATE TABLE T_MDS_STOCKSTATUSRULE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCTRLSTRATEGY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEDATAID BIGINT DEFAULT 0 NOT NULL,
FBITINDEX BIGINT DEFAULT 0 NOT NULL,
FSOURCEBITINDEX BIGINT DEFAULT 0 NOT NULL,
FTARGETENTITY NVARCHAR(80) DEFAULT ' ' NOT NULL,
FTARGETSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_STOCKSTATUSRULE_L') 
 CREATE TABLE T_MDS_STOCKSTATUSRULE_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_STOCKUPRECORD') 
 CREATE TABLE T_MDS_STOCKUPRECORD (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FPLANID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FBACKUPBOM BIGINT DEFAULT 0 NOT NULL,
FBACKUPCUSTMOR BIGINT DEFAULT 0 NOT NULL,
FBACKUPHIS BIGINT DEFAULT 0 NOT NULL,
FCONFIGURATION BIGINT DEFAULT 0 NOT NULL,
FQUERYINDEX NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPOLARISSTATUS BIGINT DEFAULT 0 NOT NULL,
FSTOCKUPMODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLTYPE VARCHAR(36) DEFAULT ' ' NOT NULL,
FPLANCODE NVARCHAR(80) DEFAULT ' ' NOT NULL
);



/**End D:\k3Cloud\PDM_UPGRADE\PDM1\MDS_table.sql **/
