/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\EB_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_COPYRECORDDT') 
 CREATE TABLE T_EB_COPYRECORDDT (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FDATATYPEID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_COPYRECORDP') 
 CREATE TABLE T_EB_COPYRECORDP (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FPERIODID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_VERSIONCOPYRECORD') 
 CREATE TABLE T_EB_VERSIONCOPYRECORD (
FID BIGINT DEFAULT 0 NOT NULL,
FEXECUTOR BIGINT DEFAULT 0 NOT NULL,
FEXECUTETIME DATETIME,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FMSG NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FPERIODTEXT NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FDATATYPETEXT NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FEXECUTEPARAM NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FSRCVERSIONID BIGINT DEFAULT 0 NOT NULL,
FTARVERSIONID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_INTEGRATION' AND KSQL_COL_NAME ='FEASMODEL') 
 ALTER TABLE T_EB_INTEGRATION ADD (FEASMODEL NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BROADCASE' AND KSQL_COL_NAME ='FIGNOREAGG') 
 ALTER TABLE T_EB_BROADCASE ADD (FIGNOREAGG CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_COPYRECORDTRIAL') 
 CREATE TABLE T_EB_COPYRECORDTRIAL (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FTRIALID BIGINT DEFAULT 0 NOT NULL,
FSOURCE CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_ROLLCONFIG' AND KSQL_COL_NAME ='FDESCRIPTION') 
 ALTER TABLE T_EB_ROLLCONFIG ADD (FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DATAUPLOADLOG' AND KSQL_COL_NAME ='FNAME') 
 ALTER TABLE T_EB_DATAUPLOADLOG ADD (FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DATAUPLOADLOG' AND KSQL_COL_NAME ='FDESCRIPTION') 
 ALTER TABLE T_EB_DATAUPLOADLOG ADD (FDESCRIPTION NVARCHAR(500) DEFAULT ' ' NOT NULL );
 EXEC p_AlterColumn 'T_EB_DATAUPLOADSCHEME', 'FNUMBER', 'NVARCHAR(50)', 'NOT NULL', '0100', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_DATAUPLOADSCHEME' AND KSQL_COL_NAME ='FDESCRIPTION') 
 ALTER TABLE T_EB_DATAUPLOADSCHEME ADD (FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL );
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BIZRULEOPTIMIZE' AND KSQL_COL_NAME ='FMAXSCOPEVALUE') 
 ALTER TABLE T_EB_BIZRULEOPTIMIZE ADD (FMAXSCOPEVALUE INT DEFAULT 0 NOT NULL );
 
  IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_MODEL' AND KSQL_COL_NAME ='FDATASOURCE') 
 ALTER TABLE T_EB_MODEL ADD (FDATASOURCE BIGINT DEFAULT 0 NOT NULL );
 
 
   IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_INTEGRATION' AND KSQL_COL_NAME ='FSRCSINGLEMETRIC') 
 ALTER TABLE T_EB_INTEGRATION ADD (FSRCSINGLEMETRIC NVARCHAR(50) DEFAULT ' ' NOT NULL );
   IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_INTEGRATION' AND KSQL_COL_NAME ='FTARGETOBJID') 
 ALTER TABLE T_EB_INTEGRATION ADD (FTARGETOBJID   BIGINT DEFAULT 0 NOT NULL);
 
 

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