
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FISPSYNC') 
  ALTER TABLE T_PMPD_PROJECT_MCC ADD (FISPSYNC CHAR(1) DEFAULT '0' NOT NULL);
  
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FPSOURCETYPE') 
  ALTER TABLE T_PMPD_PROJECT_MCC ADD (FPSOURCETYPE VARCHAR(30) DEFAULT ' ' NOT NULL);
  
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FPDUNIT') 
  ALTER TABLE T_PMPD_PROJECT_MCC ADD (FPDUNIT VARCHAR(30) DEFAULT ' ' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FESTPERIOD') 
  ALTER TABLE T_PMPD_PROJECT_MCC ADD (FESTPERIOD BIGINT DEFAULT 0 NOT NULL);
  
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FPLANPERIOD') 
  ALTER TABLE T_PMPD_PROJECT_MCC ADD (FPLANPERIOD BIGINT DEFAULT 0 NOT NULL);
  
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FREALPERIOD') 
  ALTER TABLE T_PMPD_PROJECT_MCC ADD (FREALPERIOD BIGINT DEFAULT 0 NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FTAXORGID') 
  ALTER TABLE T_PMPD_PROJECT_MCC ADD (FTAXORGID BIGINT DEFAULT 0 NOT NULL);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FMM_PROJECT_MCC_CUST')
CREATE TABLE T_FMM_PROJECT_MCC_CUST
(
	FID 					        BIGINT 	                   DEFAULT 0   NOT NULL, 		
	FENTRYID        	            BIGINT 	                   DEFAULT 0   NOT NULL,       
	FSEQ           		            INT  	                   DEFAULT 0   NOT NULL,       
	FPSOURCETYPEID 		            NVARCHAR(50)               DEFAULT ' ' NOT NULL,       
	FSOURCENUMBER 			        NVARCHAR(30)               DEFAULT ' ' NOT NULL,       
	FCUSTOMERID 			        BIGINT                     DEFAULT 0   NOT NULL  
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FMM_PROJECT_CHANGE')
CREATE TABLE T_FMM_PROJECT_CHANGE
(
	FID 			  		     	BIGINT				        DEFAULT 0   NOT NULL,					
	FNAME 					     	NVARCHAR(255)               DEFAULT ' ' NOT NULL,                      
	FFULLNAME 				   	    NVARCHAR(255)               DEFAULT ' ' NOT NULL,                      
	FNUMBER					     	NVARCHAR(30)                DEFAULT ' ' NOT NULL,                       
	FSTATUS 				     	CHAR(1)                     DEFAULT ' ' NOT NULL,                      
	FCREATORID 				   	    BIGINT                      DEFAULT 0   NOT NULL,                      
	FMODIFIERID 			   	    BIGINT                      DEFAULT 0   NOT NULL,                       
	FENABLE 				     	CHAR(1)                     DEFAULT ' ' NOT NULL,                     
	FCREATETIME 			     	DATETIME,                       		                             
	FMODIFYTIME 			     	DATETIME,                      			                                
	FMASTERID 				  	    BIGINT                      DEFAULT 0   NOT NULL,                       
	FEPSID 					        BIGINT                      DEFAULT 0   NOT NULL,                    	 
	FORGID 					  	    BIGINT                      DEFAULT 0   NOT NULL,                       
	FCREATEORGID 			     	BIGINT                      DEFAULT 0   NOT NULL,                        
	FCTRLSTRATEGY                   NVARCHAR(5)                 DEFAULT ' ' NOT NULL,                    	 
	FSOURCEDATAID 			     	BIGINT                      DEFAULT 0   NOT NULL,                      
	FBITINDEX 				  	    INT                         DEFAULT 0   NOT NULL,                        
	FSOURCEBITINDEX 		       	INT                         DEFAULT 0   NOT NULL,                       
	FCUSTOMERID 			   	    BIGINT                      DEFAULT 0   NOT NULL,                      
	FPJMANAGERID 			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FPJMGLEVEL 				        NVARCHAR(5)                 DEFAULT ' ' NOT NULL,                   	 
	FRESBALLEVEL 			        INT                         DEFAULT 0   NOT NULL,                      
	FEXPSTARTDATE 			        DATETIME,                   				                     
	FEXPFINSHDATE 			        DATETIME,                    		                                 
	FCURRENCYID 			  	    BIGINT                      DEFAULT 0   NOT NULL,                       
	FESTREVAMOUNT 			     	DECIMAL(23,10)              DEFAULT 0   NOT NULL,
	FESTCOSTAMOUNT 			       	DECIMAL(23,10)              DEFAULT 0   NOT NULL,
	FPJTYPEID 				     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FSRCBILLID 				     	NVARCHAR(50)                DEFAULT ' ' NOT NULL,                    
	FSRCSYS 				     	NVARCHAR(50)                DEFAULT ' ' NOT NULL,                     
	FSRCBILLENTITY 			        NVARCHAR(50)                DEFAULT ' ' NOT NULL,                   
	FAUDITORID 				   	    BIGINT                      DEFAULT 0   NOT NULL,                       
	FAUDITDATE 				     	DATETIME,		                                                     
	FISLEAF 				     	CHAR(1)                     DEFAULT ' ' NOT NULL,                    
	FPARENTID 				  	    BIGINT                      DEFAULT 0   NOT NULL,                       
	FPJSTATU 				     	NVARCHAR(5)                 DEFAULT ' ' NOT NULL,                       
	FISBDPROJECT 			        CHAR(1)                     DEFAULT ' ' NOT NULL,                     
	FPLANMODE 				     	NVARCHAR(5)                 DEFAULT ' ' NOT NULL,                       
	FPJSTAGEID 				     	BIGINT                      DEFAULT 0   NOT NULL,                      
	FPLANSTARTDATE 			        DATETIME,						                              
	FPLANFINSHDATE 			        DATETIME,						                              	
	FPLANSTARTTIME 			        DATETIME,						                               	
	FPRESCHEDATE 			        DATETIME,						                             	
	FREALSTARTDATE 			        DATETIME,						                              	
	FSCHEATTR 				        NVARCHAR(5)                 DEFAULT ' ' NOT NULL,                   	
	FWORKDAYTYPE 			        NVARCHAR(5)                 DEFAULT ' ' NOT NULL,                   	
	FJOBCOMPPERTYPE 		        NVARCHAR(5)                 DEFAULT ' ' NOT NULL,                    	
	FPERTIMEUNIT 			        NVARCHAR(5)                 DEFAULT ' ' NOT NULL,                    	
	FJOBCODEPREFIX 			        NVARCHAR(50)                DEFAULT ' ' NOT NULL,                   	
	FJOBCODEPREINCRE 		        DECIMAL(23,10)              DEFAULT 0   NOT NULL,
	FPJCALEID 				     	BIGINT                      DEFAULT 0   NOT NULL,                     
	FSUMCOST 				        DECIMAL(23,10)              DEFAULT 0   NOT NULL,
	FLEVEL 					  	    INT                         DEFAULT 0   NOT NULL,                   
	FLONGNUMBER 			   	    NVARCHAR(255)               DEFAULT ' ' NOT NULL,                   
	FSYNCDATE 				     	DATETIME,						                               
	FREALFINSHDATE 			        DATETIME,						                              
	FACCOUNTORGID 			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FPURCHASEORGID 			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FSALEORGID 				     	BIGINT                      DEFAULT 0   NOT NULL,                        
	FPRODUCTORGID 			     	BIGINT                      DEFAULT 0   NOT NULL,                        
	FQUALITYORGID 			     	BIGINT                      DEFAULT 0   NOT NULL,                        
	FASSETSORGID 			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FCAPITALORGID 			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FSHARECENTERID			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FHRORGID 				   	    BIGINT                      DEFAULT 0   NOT NULL,                      
	FISPSYNC    			     	CHAR(1)                     DEFAULT ' ' NOT NULL,                       
	FPSOURCETYPE			     	NVARCHAR(30)                DEFAULT ' ' NOT NULL,                     
	FPDUNIT  				     	NVARCHAR(30)                DEFAULT ' ' NOT NULL,                      
	FESTPERIOD  			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FPLANPERIOD 			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FREALPERIOD 			     	BIGINT                      DEFAULT 0   NOT NULL,                      
	FTAXORGID    			     	BIGINT                      DEFAULT 0   NOT NULL,                       
	FPNUMBER				     	NVARCHAR(30)                DEFAULT ' ' NOT NULL               
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FMM_PCHANG_CUST')
CREATE TABLE T_FMM_PCHANG_CUST
(
	FID 			                BIGINT    		           DEFAULT 0   NOT NULL,
	FENTRYID                        BIGINT                     DEFAULT 0   NOT NULL,            
	FSEQ                            INT                        DEFAULT 0   NOT NULL,           
	FPSOURCETYPEID 	            	NVARCHAR(50)               DEFAULT ' ' NOT NULL,            
	FSOURCENUMBER 	            	NVARCHAR(30)               DEFAULT ' ' NOT NULL,           
	FCUSTOMERID 	            	BIGINT                     DEFAULT 0   NOT NULL    		
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FMM_PCHANGELOG')
CREATE TABLE T_FMM_PCHANGELOG
(
	FID 					      	BIGINT				       DEFAULT 0   NOT NULL,				
	FBILLNO 				      	NVARCHAR(30)               DEFAULT ' ' NOT NULL,           
	FBILLSTATUS 			      	NVARCHAR(50)               DEFAULT ' ' NOT NULL,           
	FCHANGEPERID 			      	BIGINT                     DEFAULT 0   NOT NULL,              
	FMODIFIERID 			      	BIGINT                     DEFAULT 0   NOT NULL,              
	FAUDITORID 				      	BIGINT                     DEFAULT 0   NOT NULL,              
	FAUDITDATE 				      	DATETIME, 								             
	FMODIFYTIME 			      	DATETIME, 								              
	FCHANGETIME 			      	DATETIME, 								              
	FPNUMBER 				      	NVARCHAR(30)               DEFAULT ' ' NOT NULL,           
	FPNAME 					      	NVARCHAR(50)               DEFAULT ' ' NOT NULL,            
	FREASON 				      	NVARCHAR(255)              DEFAULT ' ' NOT NULL,
	FSTATUS 				      	NVARCHAR(30)               DEFAULT ' ' NOT NULL,           
	FPCNUMBER 				      	NVARCHAR(30)               DEFAULT ' ' NOT NULL 
);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FMM_PCHANGELOG_ENTRY')
CREATE TABLE T_FMM_PCHANGELOG_ENTRY
(
	FID 							BIGINT			          DEFAULT 0    NOT NULL, 		
	FENTRYID 						BIGINT                    DEFAULT 0    NOT NULL,         
	FSEQ 							INT                       DEFAULT 0    NOT NULL,         
	FPFIELD 						NVARCHAR(50)              DEFAULT ' '  NOT NULL, 		
	FCHANGEAFTER 					NVARCHAR(50)              DEFAULT ' '  NOT NULL, 		
	FENTRYSEQ 						BIGINT                    DEFAULT 0    NOT NULL, 			
	FCHANGEBEFORE 					NVARCHAR(50)              DEFAULT ' '  NOT NULL			
);


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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_FMM_PROJECT_CHANGE' AND KSQL_COL_NAME ='FREASON')
ALTER TABLE T_FMM_PROJECT_CHANGE ADD (FREASON NVARCHAR(255) DEFAULT ' ' NOT NULL);

