/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\BASE_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_ROUTERACTENTRY' AND KSQL_COL_NAME ='FACTRESOURCEID') 
 ALTER TABLE T_BD_ROUTERACTENTRY ADD (FACTRESOURCEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_ROUTERACTENTRY' AND KSQL_COL_NAME ='FACTSCHEDULING') 
 ALTER TABLE T_BD_ROUTERACTENTRY ADD (FACTSCHEDULING CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_MATERIAL_S' AND KSQL_COL_NAME ='FCOMPLETETAG') 
 ALTER TABLE T_BD_MATERIAL_S ADD (FCOMPLETETAG CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_PRODUCTGROUP') 
 CREATE TABLE T_BD_PRODUCTGROUP (
FID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSTANDARDID BIGINT DEFAULT 0 NOT NULL,
FISPRESET CHAR(1) DEFAULT '0' NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FLONGNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FISLEAF CHAR(1) DEFAULT '1' NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FSTATUS VARCHAR(10) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FINDUSTRIALTYPE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FZNNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCATEGORY NVARCHAR(30) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_PRODUCTGROUP_L') 
 CREATE TABLE T_BD_PRODUCTGROUP_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,
FFULLNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_MATERIAL' AND KSQL_COL_NAME ='FOFFERINGCODE') 
 ALTER TABLE T_BD_MATERIAL ADD (FOFFERINGCODE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERADDRESS' AND KSQL_COL_NAME ='FSUPPLIERADDRSSPURPOSE') 
 ALTER TABLE T_BD_SUPPLIERADDRESS ADD (FSUPPLIERADDRSSPURPOSE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERADDRESS' AND KSQL_COL_NAME ='FCUSTOMERADDRSSPURPOSE') 
 ALTER TABLE T_BD_SUPPLIERADDRESS ADD (FCUSTOMERADDRSSPURPOSE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERADDRESS' AND KSQL_COL_NAME ='FLONGITUDE') 
 ALTER TABLE T_BD_SUPPLIERADDRESS ADD (FLONGITUDE NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERADDRESS' AND KSQL_COL_NAME ='FDIMENSIONALITY') 
 ALTER TABLE T_BD_SUPPLIERADDRESS ADD (FDIMENSIONALITY NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERADDRESS' AND KSQL_COL_NAME ='FADMINDIVISIONDATA') 
 ALTER TABLE T_BD_SUPPLIERADDRESS ADD (FADMINDIVISIONDATA BIGINT DEFAULT 0 NOT NULL ); 



IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERLINKMAN' AND KSQL_COL_NAME ='FFAMILYNAME') 
 ALTER TABLE T_BD_SUPPLIERLINKMAN ADD (FFAMILYNAME NVARCHAR(150) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERLINKMAN' AND KSQL_COL_NAME ='FGIVENNAME') 
 ALTER TABLE T_BD_SUPPLIERLINKMAN ADD (FGIVENNAME NVARCHAR(150) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERLINKMAN' AND KSQL_COL_NAME ='FMIDDLENAME') 
 ALTER TABLE T_BD_SUPPLIERLINKMAN ADD (FMIDDLENAME NVARCHAR(150) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERLINKMAN' AND KSQL_COL_NAME ='FALIAS') 
 ALTER TABLE T_BD_SUPPLIERLINKMAN ADD (FALIAS NVARCHAR(150) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERLINKMAN' AND KSQL_COL_NAME ='FASSOCIATEDADDRESS') 
 ALTER TABLE T_BD_SUPPLIERLINKMAN ADD (FASSOCIATEDADDRESS BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERLINKMAN' AND KSQL_COL_NAME ='FADDRESSPURPOSE') 
 ALTER TABLE T_BD_SUPPLIERLINKMAN ADD (FADDRESSPURPOSE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERLINKMAN' AND KSQL_COL_NAME ='FFAMILYNAME') 
 ALTER TABLE T_BD_CUSTOMERLINKMAN ADD (FFAMILYNAME NVARCHAR(150) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERLINKMAN' AND KSQL_COL_NAME ='FGIVENNAME') 
 ALTER TABLE T_BD_CUSTOMERLINKMAN ADD (FGIVENNAME NVARCHAR(150) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERLINKMAN' AND KSQL_COL_NAME ='FMIDDLENAME') 
 ALTER TABLE T_BD_CUSTOMERLINKMAN ADD (FMIDDLENAME NVARCHAR(150) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERLINKMAN' AND KSQL_COL_NAME ='FALIAS') 
 ALTER TABLE T_BD_CUSTOMERLINKMAN ADD (FALIAS NVARCHAR(150) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERLINKMAN' AND KSQL_COL_NAME ='FASSOCIATEDADDRESS') 
 ALTER TABLE T_BD_CUSTOMERLINKMAN ADD (FASSOCIATEDADDRESS BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERLINKMAN' AND KSQL_COL_NAME ='FADDRESSPURPOSE') 
 ALTER TABLE T_BD_CUSTOMERLINKMAN ADD (FADDRESSPURPOSE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERBANK' AND KSQL_COL_NAME ='FIBANID') 
 ALTER TABLE T_BD_CUSTOMERBANK ADD (FIBANID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERBANK' AND KSQL_COL_NAME ='FIBANID') 
 ALTER TABLE T_BD_SUPPLIERBANK ADD (FIBANID VARCHAR(50) DEFAULT ' ' NOT NULL );

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