/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\GL_constraint.sql **/
 EXEC P_ALTERPK 'PK_T_AI_VCHTPL_EXTFIELD', 'T_AI_VCHTPL_EXTFIELD', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_VCHTPL_EXTFIELD') CREATE INDEX IDX_AI_VCHTPL_EXTFIELD ON T_AI_VCHTPL_EXTFIELD ( FVCHFIELDNAME );


 EXEC P_ALTERPK 'PK_T_AI_VCHTPL_EXTFIELD_L', 'T_AI_VCHTPL_EXTFIELD_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_VCHTPL_EXTFIELD_L') CREATE INDEX IDX_AI_VCHTPL_EXTFIELD_L ON T_AI_VCHTPL_EXTFIELD_L ( FID ,FLOCALEID );


 EXEC P_ALTERPK 'PK_T_AI_EVENT', 'T_AI_EVENT', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENT') CREATE INDEX IDX_AI_EVENT ON T_AI_EVENT ( FNUMBER ,FEVENTCLASS ,FEVENTID );


 EXEC P_ALTERPK 'PK_T_AI_EVENT_EN', 'T_AI_EVENT_EN', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENT_EN') CREATE INDEX IDX_AI_EVENT_EN ON T_AI_EVENT_EN ( FEVENTID );


 EXEC P_ALTERPK 'PK_T_AI_EVENT_INDEX', 'T_AI_EVENT_INDEX', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENT_INDEX') CREATE INDEX IDX_AI_EVENT_INDEX ON T_AI_EVENT_INDEX ( FEVENTCLASSID ,FFIELDNAME ,FFIELDVALUE ,FEVENTID );


 EXEC P_ALTERPK 'PK_T_AI_EVENTBLOCK', 'T_AI_EVENTBLOCK', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTBLOCK') CREATE INDEX IDX_AI_EVENTBLOCK ON T_AI_EVENTBLOCK ( FEVENTCLASS ,FEVENTID );


 EXEC P_ALTERPK 'PK_AI_EVENTCLASS', 'T_AI_EVENTCLASS', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTCLASS') CREATE INDEX IDX_AI_EVENTCLASS ON T_AI_EVENTCLASS ( FNUMBER );


 EXEC P_ALTERPK 'PK_T_AI_EVENTCLASS_L', 'T_AI_EVENTCLASS_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTCLASS_L') CREATE INDEX IDX_AI_EVENTCLASS_L ON T_AI_EVENTCLASS_L ( FID ,FLOCALEID );


 EXEC P_ALTERPK 'PK_T_AI_EVENTCONSUMER', 'T_AI_EVENTCONSUMER', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTCONSUMER') CREATE INDEX IDX_AI_EVENTCONSUMER ON T_AI_EVENTCONSUMER ( FNUMBER );


 EXEC P_ALTERPK 'PK_T_AI_EVENTCONSUMER_L', 'T_AI_EVENTCONSUMER_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTCONSUMER_L') CREATE INDEX IDX_AI_EVENTCONSUMER_L ON T_AI_EVENTCONSUMER_L ( FID ,FLOCALEID );


 EXEC P_ALTERPK 'PK_T_AI_EVENTENTRY_L', 'T_AI_EVENTENTRY_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTENTRY_L') CREATE INDEX IDX_AI_EVENTENTRY_L ON T_AI_EVENTENTRY_L ( FDETAILID ,FLOCALEID );


 EXEC P_ALTERPK 'PK_T_AI_EVENTFIELDS_L', 'T_AI_EVENTFIELDS_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTFIELDS_L') CREATE INDEX IDX_AI_EVENTFIELDS_L ON T_AI_EVENTFIELDS_L ( FENTRYID ,FLOCALEID );


 EXEC P_ALTERPK 'PK_T_AI_EVENTGROUP', 'T_AI_EVENTGROUP', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTGROUP') CREATE INDEX IDX_AI_EVENTGROUP ON T_AI_EVENTGROUP ( FNUMBER );


 EXEC P_ALTERPK 'PK_T_AI_EVENTGROUP_ASSIGN', 'T_AI_EVENTGROUP_ASSIGN', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTGROUP_ASSIGN') CREATE UNIQUE INDEX IDX_AI_EVENTGROUP_ASSIGN ON T_AI_EVENTGROUP_ASSIGN ( FEVENTGROUPID ,FAPPID ,FUSEORGID );


 EXEC P_ALTERPK 'PK_T_AI_EVENTGROUP_L', 'T_AI_EVENTGROUP_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTGROUP_L') CREATE INDEX IDX_AI_EVENTGROUP_L ON T_AI_EVENTGROUP_L ( FID ,FLOCALEID );


 EXEC P_ALTERPK 'PK_T_AI_PREEVENT', 'T_AI_PREEVENT', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_PREEVENT') CREATE INDEX IDX_AI_PREEVENT ON T_AI_PREEVENT ( FID );


 EXEC P_ALTERPK 'PK_T_AI_EVENTENTRY', 'T_AI_EVENTENTRY', 'FDETAILID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTENTRY') CREATE INDEX IDX_AI_EVENTENTRY ON T_AI_EVENTENTRY ( FENTRYID );


 EXEC P_ALTERPK 'PK_T_AI_EVENTFIELDS', 'T_AI_EVENTFIELDS', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_AI_EVENTFIELDS') CREATE INDEX IDX_AI_EVENTFIELDS ON T_AI_EVENTFIELDS ( FID );



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