/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_constraint.sql **/

 EXEC P_ALTERPK 'PK_T_ER_EXPENSEPOOLBILL', 'T_ER_EXPENSEPOOLBILL', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_POOL_FBILLNO') CREATE INDEX IDX_ER_POOL_FBILLNO ON T_ER_EXPENSEPOOLBILL ( FBILLNO );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_POOL_FCREATORID') CREATE INDEX IDX_ER_POOL_FCREATORID ON T_ER_EXPENSEPOOLBILL ( FCREATORID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_POOL_FCOMPANYID') CREATE INDEX IDX_ER_POOL_FCOMPANYID ON T_ER_EXPENSEPOOLBILL ( FCOMPANYID );


 EXEC P_ALTERPK 'PK_T_ER_EXPENSEPOOLBILL_L', 'T_ER_EXPENSEPOOLBILL_L', 'FPKID', '1';

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


 EXEC P_ALTERPK 'PK_T_ER_POOLMULSEATGRADE', 'T_ER_POOLMULSEATGRADE', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_ER_POOLTRIPSEATGRADE') CREATE INDEX IDX_T_ER_POOLTRIPSEATGRADE ON T_ER_POOLMULSEATGRADE ( FBASEDATAID );


 EXEC P_ALTERPK 'PK_T_ER_INVOICEPOOLINFO', 'T_ER_INVOICEPOOLINFO', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICEPOOLINFO_FSEQ') CREATE INDEX IDX_ER_INVOICEPOOLINFO_FSEQ ON T_ER_INVOICEPOOLINFO ( FID ,FSEQ );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICEPOOL_QUERY') CREATE INDEX IDX_ER_INVOICEPOOL_QUERY ON T_ER_INVOICEPOOLINFO ( FINVOICETYPE ,FINVOICEDATE );


 EXEC P_ALTERPK 'PK_T_ER_INVOICEPOOLITEM', 'T_ER_INVOICEPOOLITEM', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICEPOOLITEM') CREATE INDEX IDX_ER_INVOICEPOOLITEM ON T_ER_INVOICEPOOLITEM ( FITEMENTRYID );

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


EXEC p_DropIdx 'IDX_ISCSETTING_L_FID', 'T_ER_ISC_SETTING_L';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ISCSETTING_L_FID_FLOCALEID') CREATE UNIQUE  CLUSTERED INDEX IDX_ISCSETTING_L_FID_FLOCALEID ON T_ER_ISC_SETTING_L ( FID ,FLOCALEID );

EXEC p_DropIdx 'IDX_TYPESETTING_ID', 'T_ER_ENTITYTYPE_L';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_TYPESETTING_ID_FLCALEID') CREATE INDEX IDX_TYPESETTING_ID_FLCALEID ON T_ER_ENTITYTYPE_L ( FID ,FLOCALEID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_EXPDETAIL_EXPITMEID') CREATE INDEX IDX_ER_EXPDETAIL_EXPITMEID ON T_ER_EXPENSEDETAIL ( FEXPENSEITEMID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_EXPDETAIL_HAPPENDATE') CREATE INDEX IDX_ER_EXPDETAIL_HAPPENDATE ON T_ER_EXPENSEDETAIL ( FHAPPENDATE );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_EXPDETAIL_REIMBURSER') CREATE INDEX IDX_ER_EXPDETAIL_REIMBURSER ON T_ER_EXPENSEDETAIL ( FREIMBURSER );

 EXEC P_ALTERPK 'PK_T_ER_POOLTRIP2MULWAYTO', 'T_ER_POOLTRIP2MULWAYTO', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_POOLTRIPMULWAYTO') CREATE UNIQUE INDEX IDX_ER_POOLTRIPMULWAYTO ON T_ER_POOLTRIP2MULWAYTO ( FID ,FPKID ,FBASEDATAID );



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