IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_DATALOG')
CREATE TABLE T_ER_DATALOG (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOPNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOPDESC NVARCHAR(200) DEFAULT ' ' NOT NULL,
FOPDATE DATETIME,
FLARGEDATA NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLARGEDATA_TAG NCLOB DEFAULT ' ',
FBILLNO VARCHAR(50) DEFAULT ' ' NOT NULL,
FFORMID VARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLENTITY VARCHAR(50) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_DATALOG', 'T_ER_DATALOG', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_ER_DATALOG' AND KSQL_INDNAME = 'IDX_ER_DATALOG_FUSERNAME') CREATE INDEX IDX_ER_DATALOG_FUSERNAME ON T_ER_DATALOG ( FUSERNAME );
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_ER_DATALOG' AND KSQL_INDNAME = 'IDX_ER_DATALOG_FOPNAME') CREATE INDEX IDX_ER_DATALOG_FOPNAME ON T_ER_DATALOG ( FOPNAME );
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_ER_DATALOG' AND KSQL_INDNAME = 'IDX_ER_DATALOG_FOPDESC') CREATE INDEX IDX_ER_DATALOG_FOPDESC ON T_ER_DATALOG ( FOPDESC );
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_ER_DATALOG' AND KSQL_INDNAME = 'IDX_ER_DATALOG_FOPDATE') CREATE INDEX IDX_ER_DATALOG_FOPDATE ON T_ER_DATALOG ( FOPDATE );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_DATALOG' AND KSQL_COL_NAME ='FTRACEID') ALTER TABLE T_ER_DATALOG ADD (FTRACEID VARCHAR(50) DEFAULT ' ' );


