EXEC P_ALTERPK 'PK_IM_BGRECORD', 'T_IM_BGRECORD', 'FID', '1';
EXEC P_ALTERPK 'PK_IM_BGRECORDE', 'T_IM_BGRECORDE', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGRECORD_GVS') CREATE INDEX IDX_IM_BGRECORD_GVS ON T_IM_BGRECORD (FGROUPVALUE,FBGSETTING);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGRECORD_UPT') CREATE INDEX IDX_IM_BGRECORD_UPT ON T_IM_BGRECORD (FUPDATETIME);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGRECORDE_BDOWNMAT') CREATE INDEX IDX_IM_BGRECORDE_BDOWNMAT ON T_IM_BGRECORDE (FBOOKDATE,FOWNERID,FMATERIALID);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGRECORDE_BF') CREATE INDEX IDX_IM_BGRECORDE_BF ON T_IM_BGRECORDE (FBIZBILLID,FFORMID);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGRECORDE_BNO') CREATE INDEX IDX_IM_BGRECORDE_BNO ON T_IM_BGRECORDE (FBILLNO);

EXEC P_ALTERPK 'PK_IM_BGSET', 'T_IM_BGSET', 'FID', '1';
EXEC P_ALTERPK 'PK_IM_BGSET_L', 'T_IM_BGSET_L', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGSET_NO') CREATE INDEX IDX_IM_BGSET_NO ON T_IM_BGSET (FNUMBER);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGSET_NE') CREATE INDEX IDX_IM_BGSET_NE ON T_IM_BGSET (FNAME);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGSET_LOCAL') CREATE INDEX IDX_IM_BGSET_LOCAL ON T_IM_BGSET_L (FID ,FLOCALEID );

EXEC P_ALTERPK 'PK_IM_BGSETENTRY', 'T_IM_BGSETENTRY', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGSETENTRY_ID') CREATE INDEX IDX_IM_BGSETENTRY_ID ON T_IM_BGSETENTRY (FID);
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGSETENTRY_FORMTYPE') CREATE INDEX IDX_IM_BGSETENTRY_FORMTYPE ON T_IM_BGSETENTRY (FFORMID,FTYPE);

EXEC P_ALTERPK 'PK_IM_BGSETENTRY_L', 'T_IM_BGSETENTRY_L', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGSETENTRY_LOCAL') CREATE INDEX IDX_IM_BGSETENTRY_LOCAL ON T_IM_BGSETENTRY_L ( FENTRYID ,FLOCALEID );

EXEC P_ALTERPK 'PK_IM_BGSETRENTRY', 'T_IM_BGSETRENTRY', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IM_BGSETRENTRY_ID') CREATE INDEX IDX_IM_BGSETRENTRY_ID ON T_IM_BGSETRENTRY (FID);

