See below the script for MS SQL. The script will go through all relationships and add the index “IX_RelationshipName” to all child entities. The script ensures that index of the same name will not be created if the script is executed more times.
If you have any questions, please write us back. Thanks.
var i, j, Relation, ChildEntity, IndexName, Index, IndexItem, Attribute;
var app = System.GetInterface(“Application”);
var Model = app.Models.GetObject(0);
//The parameter in GetObject determines here with which model the script should work.
//0 is the first model listed in the Application View.
//1 is the second model listed in the Application View, etc.
for(i=0; i<Model.Relations.Count; i++)
Relation = Model.Relations.GetObject( i );
ChildEntity = Relation.ChildEntity;
IndexName = “IX_”+Relation.Name;
if (ChildEntity.Indexes.GetObjectByName(IndexName) == null)
Index = ChildEntity.CreateNewObject( 2012 );
//Create new Index (2012 is object type of PERIndex)
Index.Name = IndexName;
for (j=0; j<Relation.ForeignKeys.Count; j++)
Attribute = Relation.ForeignKeys.GetObject(j).AttrChild;
IndexItem = Index.CreateNewObject( 2013 );
//Create new Item of Index (2013 is object type of PERIndexItem)
IndexItem.Attribute = Attribute;
Log.Information("Index “+IndexName+” created on table "+ChildEntity.Name);
Vladka + Mario
P.S. Unfortunately, the community doesn’t allow me to attach files today. Don’t know why. Sorry.
Message was edited by: vladka