Toad World® Forums

Automatic name for a column


#1

Hello,

I want to name a column depending on the name of the tablename. But I dont know how to do it. for example when the tablename is “MyTable” the column name should be “PK_MyTable”. Of course I could just name it, but when the tablename changes, I need to change the column name aswell. is there any way to add a tablename automatic to the columnname, like PK_%tablename% ? Or even better is there a website I can see all “programming magic” you can do for objekt and column names.

thanks
Ilja


#2

Hi Ilja,

Scripting can solve it.

Script 1
This script goes through all attributes of your model and if it doesn’t find the “" character, it will add the table in the following format: “TableName" to the attribute name.
If the script finds the "
” character, it will change just the text after "
” according to the entity name.

Script2
Use script 2 if you need to use the “" character also in other places. (In such case, script 1 would rename also items you do not want to rename.)
For script 2, it is necessary to write e.g. "AttributeName
%tablename%” to the Caption box of attribute. Then the script will change the Name this way: it will take the Caption and replaces %tablename% with an actual entity name in which the attribute is.

Please run the selected script in Scripting Window (Tools menu). Expert mode must be on: Settings | Options | General | Expert mode checkbox.

If you have any questions, please write us back. Thanks.

Regards,

Vladka + Mario
script2.js (932 Bytes)


#3

Hi Ilja,

Scripting can solve it.

Script 1
This script goes through all attributes of your model and if it doesn’t find the “" character, it will add the table in the following format: “TableName" to the attribute name.
If the script finds the "
” character, it will change just the text after "
” according to the entity name.

Script2
Use script 2 if you need to use the “" character also in other places. (In such case, script 1 would rename also items you do not want to rename.)
For script 2, it is necessary to write e.g. "AttributeName
%tablename%” to the Caption box of attribute. Then the script will change the Name this way: it will take the Caption and replaces %tablename% with an actual entity name in which the attribute is.

Please run the selected script in Scripting Window (Tools menu). Expert mode must be on: Settings | Options | General | Expert mode checkbox.

If you have any questions, please write us back. Thanks.

Regards,

Vladka + Mario
script1.js (1.01 KB)


#4

hello Vladka + Mario,

sorry for the late replay, now I have the full version (before I had the trial ) of TDM and it works fine. In future versions I would like to see that there is a function already integrated in the programm. It will safe a lot of time to “auto_name” a column. One example is, I would like to be able to create rules for my primary key column of each table like PK_tablename. so when I change the tablename, it will also change my column name.

another good idea would be to set up “auto columns”. When I create a new table, I dont need to add them by myself. Also a filter would be nice, so I can hide them in the model.

there is another issue I have, when you use shadows around the entities, the relationship symbol will be overlaped from the shadow.

Ilja


#5

Hello Ilja,

Thanks for your suggestions!

  1. internal macros - CR # 38 986

  2. Auto columns - CR # 64 898

  3. Filter tables- CR # 64 899

Thanks again.

Regards,

Vladka + TDM Team