IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_BOMVERSION' AND KSQL_COL_NAME ='FECNBILLNO') 
 ALTER TABLE T_BD_BOMVERSION ADD (FECNBILLNO VARCHAR(60) DEFAULT ' ' NOT NULL );

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

-- BOM版本规则
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_BOMVERSIONRULE') 
 CREATE TABLE T_BD_BOMVERSIONRULE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(60) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCTRLSTRATEGY VARCHAR(30) DEFAULT ' ' NOT NULL,
FTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FISDEFAULT CHAR(1) DEFAULT '1' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_BOMVERSIONRULE_L') 
 CREATE TABLE T_BD_BOMVERSIONRULE_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_BD_BOMVERSIONRULEENTRY') 
 CREATE TABLE T_BD_BOMVERSIONRULEENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL
);

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