Toad World® Forums

Script to change Alternate Key Names & Captions

I’ve been able to rename Entities, Attributes, Foreign Keys, and View Relationships.

I’m stuck on Alternate Keys, would anyone be able to help, thanks in advance.

Also I’ve been teaching myself to use the scripting library but I can’t seem to find documentation on simple things, like the object property IsPrimaryKey. I thought there may be IsAlternateKey. Where would such a property be documented?


a list of objects and available properties can be found in Reference Guide.


Look for PEREntity (PER = Physical Entity Relationship) and try to iterate keys. If key property IsPrimaryKey is not true, then it is alternate key.

If you want to find out whether attribute is part of alternate key, use this script:

var Log = System.CreateObject("Log");

var e, iterEntity, i, iterAttribute, a, PKAttr, FKAttr;
var KeyItem, Key

for (e = 0; e < Model.Entities.Count; e++) // iterate entities
    iterEntity = Model.Entities.GetObject(e);

    for (i = 0; i < iterEntity.Attributes.Count; i++)
    // iterate attributes
        iterAttribute = iterEntity.Attributes.GetObject(i);

        for (var a=0; a<iterAttribute.KeyConstraintItems.Count; a++)
             KeyItem = iterAttribute.KeyConstraintItems.GetObject(a);
             Key = KeyItem.Owner;
             if (! Key.IsPrimaryKey)
               Log.Information("Attribute " + iterAttribute.Name + " in entity " + iterEntity.Name +" is part of alternate key " + Key.Name);

System.ShowMessageDialog(1004, 'MessageDialog', 'Finished! See log for more information.                          ', 2, 4 );


Good luck!

Vaclav & Mario