Toad World® Forums

Macro to rename index on foreign key

Hi,

TDM version : 6.0

Requirement:

My requirement is to rename foreign key indexes with suffix based on following condition: tablename_columnname(s)_fk_i


What I tried so far:

I searched the PERIndex and PERIndexItem properties, but I couldn’t find the property to check the condition Index.Foreign similar toIndex.Unique.


if (Index.Unique)
{
suffix = “_uk_i”;
}

// How to rename foreign index

** else if (Index.Foreign)**
** {**
** suffix = “_fk_i”;**
** }**

else

{

suffix = “_i”;

}


Question:

How to rename the foreign index as per above code. I need to implement following rule : tablename_columnnames(s)_fk_i


Regards,

Lalit

Hi Lalit,

Try the following code, it detects whether the index is an index of a foreign key and if so, it displays the related relationship name:

if (Index.RelationSource!=null)
{
Log.Information('Index is linked to Relation: '+Index.RelationSource.Name);
}
else
{
Log.Information(‘Normal Index’);
}

Regards,

Lukas

Hi Lukas,

Thanks a lot! It worked.

For what it’s worth, I would like to know how to find these properties which can’t be found in Reference Guide. I see the property only in Class viewer under PERIndexPG92, but the same is not mentioned in Reference Guide under classes.

You can find all this information in Reference Guide, it’s just that it is updated once every couple of releases as there are not that many users that use advanced features such as scripting and customization.

However, feel free to ask us here anytime!

Regards,

Lukas