/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\SBD_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMOVETRACK' AND KSQL_COL_NAME ='FBILLENTRYTYPE') 
 ALTER TABLE T_BD_SNMOVETRACK ADD (FBILLENTRYTYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMOVETRACK' AND KSQL_COL_NAME ='FBILLENTRYID') 
 ALTER TABLE T_BD_SNMOVETRACK ADD (FBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMOVETRACK' AND KSQL_COL_NAME ='FINCREASEINVCOUNTER') 
 ALTER TABLE T_BD_SNMOVETRACK ADD (FINCREASEINVCOUNTER BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMOVETRACK' AND KSQL_COL_NAME ='FSUBSTRACTINVCOUNTER') 
 ALTER TABLE T_BD_SNMOVETRACK ADD (FSUBSTRACTINVCOUNTER BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMOVETRACK' AND KSQL_COL_NAME ='FTRAINCREASEINVCOUNTER') 
 ALTER TABLE T_BD_SNMOVETRACK ADD (FTRAINCREASEINVCOUNTER BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMOVETRACK' AND KSQL_COL_NAME ='FTRASUBSTRACTINVCOUNTER') 
 ALTER TABLE T_BD_SNMOVETRACK ADD (FTRASUBSTRACTINVCOUNTER BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMOVETRACK' AND KSQL_COL_NAME ='FSRCINVORGID') 
 ALTER TABLE T_BD_SNMOVETRACK ADD (FSRCINVORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMOVETRACK' AND KSQL_COL_NAME ='FBALANCETYPE') 
 ALTER TABLE T_BD_SNMOVETRACK ADD (FBALANCETYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_MATERIALINVINFO' AND KSQL_COL_NAME ='FSNGENTIMEPOINT') 
 ALTER TABLE T_BD_MATERIALINVINFO ADD (FSNGENTIMEPOINT VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_SNDIMENSIONENTRY') 
 CREATE TABLE T_BD_SNDIMENSIONENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSNDIMITEM BIGINT DEFAULT 0 NOT NULL,
FSNDIMNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_SNMOVETRACK_REL') 
 CREATE TABLE T_BD_SNMOVETRACK_REL (
FID BIGINT DEFAULT 0 NOT NULL,
FSNMAINFILEID BIGINT DEFAULT 0 NOT NULL,
FTRACKID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMAINFILE' AND KSQL_COL_NAME ='FOCCUPYBILLID') 
 ALTER TABLE T_BD_SNMAINFILE ADD (FOCCUPYBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMAINFILE' AND KSQL_COL_NAME ='FOCCUPYBILLTYPE') 
 ALTER TABLE T_BD_SNMAINFILE ADD (FOCCUPYBILLTYPE VARCHAR(36) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMAINFILE' AND KSQL_COL_NAME ='FSOURCEBILLTYPE') 
 ALTER TABLE T_BD_SNMAINFILE ADD (FSOURCEBILLTYPE VARCHAR(36) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMAINFILE' AND KSQL_COL_NAME ='FSOURCEBILLENTRYTYPE') 
 ALTER TABLE T_BD_SNMAINFILE ADD (FSOURCEBILLENTRYTYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMAINFILE' AND KSQL_COL_NAME ='FOCCUPYBILLENTRYTYPE') 
 ALTER TABLE T_BD_SNMAINFILE ADD (FOCCUPYBILLENTRYTYPE VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMAINFILE' AND KSQL_COL_NAME ='FSOURCEBILLENTRYID') 
 ALTER TABLE T_BD_SNMAINFILE ADD (FSOURCEBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMAINFILE' AND KSQL_COL_NAME ='FOCCUPYBILLENTRYID') 
 ALTER TABLE T_BD_SNMAINFILE ADD (FOCCUPYBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SNMAINFILE' AND KSQL_COL_NAME ='FFINALAUDITTRAILID') 
 ALTER TABLE T_BD_SNMAINFILE ADD (FFINALAUDITTRAILID BIGINT DEFAULT 0 NOT NULL );
 EXEC p_AlterColumn 'T_BD_SERVICEATTRIBUTE', 'FENTITY', 'NVARCHAR(36)', 'NOT NULL', '1111', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_SNDIMENSION_L') 
 CREATE TABLE T_BD_SNDIMENSION_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_USERTABLES WHERE KSQL_TABNAME = 'T_BD_SNDIMENSION') 
 CREATE TABLE T_BD_SNDIMENSION (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FSNCHECKRANGE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSYSTEMPRESET CHAR(1) DEFAULT '0' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);



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