/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\BASE_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_APPMATERIALS') 
 CREATE TABLE T_BD_APPMATERIALS (
FID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FBILLTYPE VARCHAR(5) DEFAULT ' ' NOT NULL,
FPROPOSER BIGINT DEFAULT 0 NOT NULL,
FFILINGDATE DATETIME,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCTRLSTRATEGY VARCHAR(5) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_APPMATERIALSENTRY') 
 CREATE TABLE T_BD_APPMATERIALSENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FAPPLYNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FMATERIALNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBASEUNITID BIGINT DEFAULT 0 NOT NULL,
FMATERIALTYPE VARCHAR(5) DEFAULT ' ' NOT NULL,
FGROUP BIGINT DEFAULT 0 NOT NULL,
FTEMPLATEMATERIAL BIGINT DEFAULT 0 NOT NULL,
FISTEMPMATERIAL CHAR(1) DEFAULT '0' NOT NULL,
FFORMALMATERIALNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FMODEL NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_APPMATERIALSENTRY_L') 
 CREATE TABLE T_BD_APPMATERIALSENTRY_L (
FPKID NVARCHAR(36) DEFAULT ' ' NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
FMODEL NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMATERIALNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERGROUPDETAIL' AND KSQL_COL_NAME ='FCREATEORGID') 
 ALTER TABLE T_BD_CUSTOMERGROUPDETAIL ADD (FCREATEORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERGROUPDETAIL' AND KSQL_COL_NAME ='FCREATEORGID') 
 ALTER TABLE T_BD_SUPPLIERGROUPDETAIL ADD (FCREATEORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_MATERIALGROUPDETAIL' AND KSQL_COL_NAME ='FCREATEORGID') 
 ALTER TABLE T_BD_MATERIALGROUPDETAIL ADD (FCREATEORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMERGROUP' AND KSQL_COL_NAME ='FCREATEORGID') 
 ALTER TABLE T_BD_CUSTOMERGROUP ADD (FCREATEORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIERGROUP' AND KSQL_COL_NAME ='FCREATEORGID') 
 ALTER TABLE T_BD_SUPPLIERGROUP ADD (FCREATEORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_MATERIALGROUP' AND KSQL_COL_NAME ='FCREATEORGID') 
 ALTER TABLE T_BD_MATERIALGROUP ADD (FCREATEORGID BIGINT DEFAULT 0 NOT NULL );

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