/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MDS_table.sql **/
 EXEC p_AlterColumn 'T_MDS_RPLANCAL', 'FSTYPE', 'NVARCHAR(20)', 'NOT NULL', '1111', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_QUOTA') 
 CREATE TABLE T_MDS_QUOTA (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS NVARCHAR(30) 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,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FUSEORGID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FLOSEDATE DATETIME,
FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FUSEORG BIGINT DEFAULT 0 NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FQUOTATYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FMATERIALNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_QUOTAINFO') 
 CREATE TABLE T_MDS_QUOTAINFO (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FALLOCATEORGID BIGINT DEFAULT 0 NOT NULL,
FQUOTAMOD DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FPREDTIME') 
 ALTER TABLE T_MDS_WRTFF ADD (FPREDTIME BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FRUNNINGTYPE') 
 ALTER TABLE T_MDS_WRTFF ADD (FRUNNINGTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FLOSEDATE') 
 ALTER TABLE T_MDS_WRTFF ADD (FLOSEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FREPEATTYPE') 
 ALTER TABLE T_MDS_WRTFF ADD (FREPEATTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FREPEAT') 
 ALTER TABLE T_MDS_WRTFF ADD (FREPEAT NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FDAYSOFWEEK') 
 ALTER TABLE T_MDS_WRTFF ADD (FDAYSOFWEEK NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FDAYSOFMON') 
 ALTER TABLE T_MDS_WRTFF ADD (FDAYSOFMON NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FBILLSTATUS') 
 ALTER TABLE T_MDS_WRTFF ADD (FBILLSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FPLANID') 
 ALTER TABLE T_MDS_WRTFF ADD (FPLANID NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_WRTFF' AND KSQL_COL_NAME ='FJOBID') 
 ALTER TABLE T_MDS_WRTFF ADD (FJOBID NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_SALORDPLAN' AND KSQL_COL_NAME ='FSUPORG') 
 ALTER TABLE T_MDS_SALORDPLAN ADD (FSUPORG BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FREMAINQTY') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FREMAINQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FEPDDATE') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FEPDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FRPDDATE') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FRPDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FSALEORG') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FSALEORG BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FOUTSTOCKQTY') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FOUTSTOCKQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FORDERREMAINQTY') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FORDERREMAINQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FBILLTYPE') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FBILLTYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FSENDGOODSDATE') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FSENDGOODSDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_ORDERSETOFF' AND KSQL_COL_NAME ='FORDERSTATUS') 
 ALTER TABLE T_MDS_ORDERSETOFF ADD (FORDERSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL );

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