
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CASWRITEBACK' AND KSQL_COL_NAME IN ('FRECID'))
ALTER TABLE T_ER_CASWRITEBACK ADD (FRECID BIGINT DEFAULT 0 NOT NULL );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CASWRITEBACK' AND KSQL_COL_NAME IN ('FVALID'))
ALTER TABLE T_ER_CASWRITEBACK ADD (FVALID CHAR(1) DEFAULT '1' NOT NULL );

--
--
-- IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CAS_LOCK')
--  CREATE TABLE T_ER_CAS_LOCK (
-- FID BIGINT DEFAULT 0 NOT NULL,
-- FENTITYID VARCHAR(30) DEFAULT ' ' NOT NULL,
-- FSOURCEID BIGINT DEFAULT 0 NOT NULL
-- );
--
-- EXEC P_ALTERPK 'PK_T_ER_CAS_LOCK', 'T_ER_CAS_LOCK', 'FID', '1';
--
--  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CAS_LOCK_SOURCEID') CREATE UNIQUE INDEX IDX_ER_CAS_LOCK_SOURCEID ON T_ER_CAS_LOCK ( FENTITYID ,FSOURCEID );