/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MRP_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANDISPATCH' AND KSQL_COL_NAME ='FREQPLANLOG1') 
 ALTER TABLE T_MRP_PLANDISPATCH ADD (FREQPLANLOG1 NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANDISPATCH' AND KSQL_COL_NAME ='FMRPLOG1') 
 ALTER TABLE T_MRP_PLANDISPATCH ADD (FMRPLOG1 NVARCHAR(50) DEFAULT ' ' NOT NULL );
 --- drop column --------- 不允许删除表T_MRP_PLANDISPATCH的字段FREQPLANLOG，请恢复pdm中的字段 ------------------- 
 --- drop column --------- 不允许删除表T_MRP_PLANDISPATCH的字段FMRPLOG，请恢复pdm中的字段 ------------------- 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_RUNCONFIG') 
 CREATE TABLE T_MRP_RUNCONFIG (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FPARAMTYPE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPARAM NVARCHAR(255) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_MQDATA') 
 CREATE TABLE T_MRP_MQDATA (
FID BIGINT DEFAULT 0 NOT NULL,
FPLANID NVARCHAR(50) DEFAULT ' ' NOT NULL,
FPLANNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FPLANNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSERVERID NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMAINNODE NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PRODFORECAST') 
 CREATE TABLE T_MRP_PRODFORECAST (
FID BIGINT DEFAULT 0 NOT NULL,
FSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FPRODUCTDEPTID BIGINT DEFAULT 0 NOT NULL,
FPRODUCTLINEID BIGINT DEFAULT 0 NOT NULL,
FPRODUCTDOMAINID BIGINT DEFAULT 0 NOT NULL,
FPRODUCTRENTID BIGINT DEFAULT 0 NOT NULL,
FPRODUCTSERIESID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FSITEID BIGINT DEFAULT 0 NOT NULL,
FREMARKS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLASTMODIFIER BIGINT DEFAULT 0 NOT NULL,
FLASTDATETIME DATETIME,
FPRODPLANNERID BIGINT DEFAULT 0 NOT NULL,
FSUPPLYMODEID BIGINT DEFAULT 0 NOT NULL,
FMODIFIED CHAR(1) DEFAULT '0' NOT NULL,
FDATEQTY NVARCHAR(30) DEFAULT ' ' NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FMACHININGTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FOFFERINGID BIGINT DEFAULT 0 NOT NULL,
FWARESET NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSOPVERSET NVARCHAR(30) DEFAULT ' ' NOT NULL,
FWARESET_TAG NCLOB,
FSOPVERSET_TAG NCLOB,
FDATEQTY_TAG NCLOB
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_SUPPLYDATA_E') 
 CREATE TABLE T_MRP_SUPPLYDATA_E (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FWASTERESERVE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FWASTECHANGED NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISREPLACE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FEXCEPTIONNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISNEWPLANORDER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSPLITSRCID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISADJUST NVARCHAR(255) DEFAULT ' ' NOT NULL,
FWASTESTORAGEDEALTIME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FADJUSTQTY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FADJUSTPLANDATE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPRIORITYLEVEL NVARCHAR(255) DEFAULT ' ' NOT NULL,
FWASTESTORAGERATIO NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMODELNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FEXCEPTIONMESSAGE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FADJUSTFLAG NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISSPLITED NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSUPPLYPRIORITY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISCENTERTRANS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBILLENTITY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISOCCUPIED NVARCHAR(255) DEFAULT ' ' NOT NULL,
FINVTAG NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMODELID NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_BOMDATA_E') 
 CREATE TABLE T_MRP_BOMDATA_E (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FBILLENTITY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMODELNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMETRICSKEY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMODELID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FYIELD NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPOSTPROCESSDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDYNAMICBATCH NVARCHAR(255) DEFAULT ' ' NOT NULL,
FWASTAGERATEFORMULA NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBILLSTATUSFIELD NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPREPROCESSDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPROJECTNUMBER1 NVARCHAR(255) DEFAULT ' ' NOT NULL,
FFIXLEADDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPRECHECKDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDYNAMICLEADDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENDTRACKNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBEGINTRACKNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLEADTYPE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FWASTAGERATE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPLANTAG NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_REQUIREDATA_E') 
 CREATE TABLE T_MRP_REQUIREDATA_E (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSTANDQTY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FXID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FYIELD NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDELAYADJUSTPERIOD NVARCHAR(255) DEFAULT ' ' NOT NULL,
FADVANCEADJUSTPERIOD NVARCHAR(255) DEFAULT ' ' NOT NULL,
FTOLEROFDELAY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FTOLEROFFORWARD NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBILLENTITY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDEMANDMERGERULE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDEFAULTPLANSTRATEGY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBOMENTRYID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBOMVERSION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCHILDTYPE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCHILDNUMERATOR NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSCRAPRATIO NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCHILDMATERIALPLAN NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPLANTAG NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPLANUSER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FNEWPOID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCHILDAMTTYPE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMATERIALPLAN NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCHILDSUPPLYTYPE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDYNAMICSCRAPFORMULA NVARCHAR(255) DEFAULT ' ' NOT NULL,
FORDERDATE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREQUIRESOURCE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FNEWPOHEADNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCHILDSCRAPRATE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSRCDATE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMODELID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FWRITTENOFFQTY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCHILDDENOMINATOR NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSPLITPRODORG NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBOMID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENDDATE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLASTSTOCK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FNEWPOENTRYID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FNEWPARENTPOID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSTARTDATE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISDIRECTTRANSREQUIRE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPRIORITYLEVEL NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCHILDFIXSCRAP NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDYNAMICSCRAPRATIO NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMODELNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISDEPENDENT NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREQUIREORGCHAIN NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_REQUIREDATA_F') 
 CREATE TABLE T_MRP_REQUIREDATA_F (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FLLC NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSPLITQTY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSUPPLYQTY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPARENTID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISCENTERTRANS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FNEWPONUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREALQUATA NVARCHAR(255) DEFAULT ' ' NOT NULL,
FFIXSCRAP NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREPLACESTRA NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPOSTPROCESSDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDYNAMICBATCH NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENTRYISREPLACE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREQUIREOPERAOTR NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMERGEBILLID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMERGEBILLENTRYID NVARCHAR(255) DEFAULT ' ' NOT NULL,
FFIXLEADDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDYNAMICLEADDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSRCDEMANDQTY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMERGEBILLENTRYSEQ NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMERGEBILLNO NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREPLACEMETHOD NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISMERGE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FEXCEPTIONNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPLANMODE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPREPROCESSDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPRECHECKDAYS NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLEADTYPE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FEXCEPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENTRYREPLACEPLAN NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENTRYPRIORITY NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_ORDERRECORD') 
 CREATE TABLE T_MRP_ORDERRECORD (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FMATERIEL BIGINT DEFAULT 0 NOT NULL,
FSALEORDER BIGINT DEFAULT 0 NOT NULL,
FRPD DATETIME,
FEPD DATETIME,
FDELEVERYDATE DATETIME,
FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSALEORDEROUTID BIGINT DEFAULT 0 NOT NULL,
FBILLTYPE BIGINT DEFAULT 0 NOT NULL,
FORDERSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACCOUTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSALEORDERUNIT BIGINT DEFAULT 0 NOT NULL,
FSALEOUTENTRYID BIGINT DEFAULT 0 NOT NULL,
FSALEOUTLINE BIGINT DEFAULT 0 NOT NULL,
FORDERNO BIGINT DEFAULT 0 NOT NULL,
FVERSIONID BIGINT DEFAULT 0 NOT NULL,
FTRANSFERID BIGINT DEFAULT 0 NOT NULL,
FRECORDDATE DATETIME
);



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