/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MRP_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_DEMANDRECORDENTRY') 
 CREATE TABLE T_MRP_DEMANDRECORDENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FCONSUMEORGID BIGINT DEFAULT 0 NOT NULL,
FCONSUMEBILLTYPEID NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCONSUMEBILLNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCONSUMEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCONSUMEENTRYSEQ INT DEFAULT 0 NOT NULL,
FCONSUMEBILLID BIGINT DEFAULT 0 NOT NULL,
FCONSUMEENTRYID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDRECORD' AND KSQL_COL_NAME ='FTOTALQTY') 
 ALTER TABLE T_MRP_DEMANDRECORD ADD (FTOTALQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDRECORD' AND KSQL_COL_NAME ='FDEMANDBILLID') 
 ALTER TABLE T_MRP_DEMANDRECORD ADD (FDEMANDBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDRECORD' AND KSQL_COL_NAME ='FDEMANDENTRYID') 
 ALTER TABLE T_MRP_DEMANDRECORD ADD (FDEMANDENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDRECORD' AND KSQL_COL_NAME ='FISDEMANDHEAD') 
 ALTER TABLE T_MRP_DEMANDRECORD ADD (FISDEMANDHEAD NVARCHAR(50) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDRECORD' AND KSQL_COL_NAME ='FISCONSUMEHEAD') 
 ALTER TABLE T_MRP_DEMANDRECORD ADD (FISCONSUMEHEAD NVARCHAR(50) DEFAULT '0' NOT NULL );
 --- drop column --------- 不允许删除表T_MRP_DEMANDRECORD的字段FCONSUMEORGID，请恢复pdm中的字段 ------------------- 
 --- drop column --------- 不允许删除表T_MRP_DEMANDRECORD的字段FCONSUMEBILLTYPEID，请恢复pdm中的字段 ------------------- 
 --- drop column --------- 不允许删除表T_MRP_DEMANDRECORD的字段FCONSUMEBILLNUMBER，请恢复pdm中的字段 ------------------- 
 --- drop column --------- 不允许删除表T_MRP_DEMANDRECORD的字段FCONSUMEQTY，请恢复pdm中的字段 ------------------- 
 --- drop column --------- 不允许删除表T_MRP_DEMANDRECORD的字段FCONSUMEENTRYSEQ，请恢复pdm中的字段 ------------------- 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDPLAN' AND KSQL_COL_NAME ='FPROJECT') 
 ALTER TABLE T_MRP_DEMANDPLAN ADD (FPROJECT NVARCHAR(60) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDPLAN' AND KSQL_COL_NAME ='FPROJECTNAME') 
 ALTER TABLE T_MRP_DEMANDPLAN ADD (FPROJECTNAME NVARCHAR(60) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDPLAN' AND KSQL_COL_NAME ='FTRACKNUMBER') 
 ALTER TABLE T_MRP_DEMANDPLAN ADD (FTRACKNUMBER NVARCHAR(60) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_DEMANDPLAN' AND KSQL_COL_NAME ='FTRACKNUMBERNAME') 
 ALTER TABLE T_MRP_DEMANDPLAN ADD (FTRACKNUMBERNAME NVARCHAR(60) DEFAULT ' ' NOT NULL );

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