Toad World® Forums

Rename Indexes Macro?


#1

I am looking for a macro or way to run a script to rename the indexes on tables (auto-generated from foreign keys) from IX_Relationship22 (IX8) to something more meaningful… like IX_[TableName]_[Column]. I have google searched and searched this community. I found posts for scripts, but have not found or seen any way to open a script and run it. Some solution scripts are from 2010, making me wonder why there is not a macro for this in the Macros menu?

If I missed something in the application or in this community, please point me in the right direction.

I am using TDM 6.3 (just got it in the past month, so many of this is new to me), but it’s quite a nice product.


#2

Hello,

I don’t understand if you have package with macro already imported to TDM. If yes, you can review this macro from package/script explorer(First switch on expert mode “Main Menu-Settings-Options-General”). Click on macro by right click and choose “Properties” you get this dialog

macros.png

On this dialog is defined where will be macro accessible. It can be from Main Menu Macros or from PopUp Menu. If it is from popup menu there is next page “Object Type”. It is define on which objects will be this macro available.

Daril


#3

Thank you for your reply. 1st, I did not know there was an Expert Mode, now turned on. Daril, from your reply, I have no idea what you are “right” clicking on to get the Macro properties dialog window. I with to rename all Indexes, just like rename all relationships.

I can now run macros that are in this menu (see image below), before when I clicked to run a macro, nothing seemed to happen. Now I can rename all Foreign Keys.

snip_20180605104345.png

I also found Script Explorer and added a script RenameIndexMacro, but do not see a way to run the script, and have not yet found a way to add this script to the menu in the image above.

I am about to just edit the Rename Relationships script to also rename the indexes.


#4

Hi,

each macro is located in package. It can be My Package or some else. Package is file on your filesystem. Could you provide this package with description where you want to run this macro(Main Menu, Popup Menu of Entity, Index…)? I can review it and modify it will be necessary.

scriptproperties1.png

PackageProperties.png

Daril


#5

Daril,

Thank you for your help, your first reply got me heading in the right direction. The solution for Macro to Rename all indexes based on table (Entity) name and table column (FK) below.

First, you need to enable “Expert Mode”, From the menu, choose Settings => Options => Expert Mode [check box]

Next, open the Scripting window.

6153.snip_20180605144203.png

Next, click on the Script Explorer button.

0777.snip_20180605144424.png

On the right side of TDM, you will see the Script Explorer. Find and expand the Macros folder. In there you will find your existing Macros used to rename Keys and Relationships.

3482.snip_20180605144731.png

Right-click on the Macros folder and choose Add New Macro. Enter your macro script here or feel free to copy the contents of my script file attached below. (***I took the index script from Michael K in this post and modified it ever so slightly so it would work as a macro.***) Rename your Macro as needed. When you’re done and want to test your Macro, right click on the macro in Script Explorer and choose Properties.

3482.snip_20180605145156.png

Now on the General tab, set the Caption to what you want… this will be the TEXT you see in the menu. Next, go to the Menu tab and adjust the Path, that determines where in the Macros menu your Macro will appear. You may need to adjust the Register Order value for the position of your macro in the menu list.

2844.snip_20180605145631.png

Now your macro will shoe in the Macro’s menu and run your macro and see how it works.

Thanks to Daril pointing me in the right direction.

Thanks to Michal.K in sharing his original script.

UPDATE: Added my RenameRelationshipsMacro instead of the “rename index macro” from Michal K.
RenameRelationsipsMacro.txt (6.76 KB)