/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\BASE_constraint.sql **/
 EXEC P_ALTERPK 'PK_T_BD_APPMATERIALS', 'T_BD_APPMATERIALS', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BD_APPMATERIALS_FORFBIZFNO') CREATE INDEX IDX_BD_APPMATERIALS_FORFBIZFNO ON T_BD_APPMATERIALS ( FORGID ,FBILLNO  DESC ,FFILINGDATE  DESC );


 EXEC P_ALTERPK 'PK_T_BD_APPMATERIALS_L', 'T_BD_APPMATERIALS_L', 'FPKID', '1';

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


 EXEC P_ALTERPK 'PK_T_BD_APPMATERIALSENTRY', 'T_BD_APPMATERIALSENTRY', 'FENTRYID', '1';

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


 EXEC P_ALTERPK 'PK_T_BD_APPMATERIALSENTRY_L', 'T_BD_APPMATERIALSENTRY_L', 'FPKID', '1';

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


EXEC p_DropIdx 'IDX_CUSTOMERGROUPDETAIL_GROUP', 'T_BD_CUSTOMERGROUPDETAIL';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CUSTOMERGROUPDETAIL_GROUP') CREATE INDEX IDX_CUSTOMERGROUPDETAIL_GROUP ON T_BD_CUSTOMERGROUPDETAIL ( FGROUPID ,FCREATEORGID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CUSTOMERGROUPDETAIL_CUS') CREATE INDEX IDX_CUSTOMERGROUPDETAIL_CUS ON T_BD_CUSTOMERGROUPDETAIL ( FCUSTOMERID );

EXEC p_DropIdx 'IDX_SUPPLIERGROUPDETAIL_GROUP', 'T_BD_SUPPLIERGROUPDETAIL';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SUPPLIERGROUPDETAIL_GROUP') CREATE INDEX IDX_SUPPLIERGROUPDETAIL_GROUP ON T_BD_SUPPLIERGROUPDETAIL ( FGROUPID ,FCREATEORGID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SUPPLIERGROUPDETAIL_SUP') CREATE INDEX IDX_SUPPLIERGROUPDETAIL_SUP ON T_BD_SUPPLIERGROUPDETAIL ( FSUPPLIERID );

EXEC p_DropIdx 'IDX_MATERIALGROUPDETAIL_GROUP', 'T_BD_MATERIALGROUPDETAIL';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_MATERIALGROUPDETAIL_GROUP') CREATE INDEX IDX_MATERIALGROUPDETAIL_GROUP ON T_BD_MATERIALGROUPDETAIL ( FGROUPID ,FCREATEORGID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_MATERIALGROUPDETAIL_MAT') CREATE INDEX IDX_MATERIALGROUPDETAIL_MAT ON T_BD_MATERIALGROUPDETAIL ( FMATERIALID );


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