'TTTLE: NAME PRIMARY CONSTRAINTS 'DESCRIPTION: This macro will name all primary key constraints ' with the given naming conventions. The table name with either ' a prefix or suffix. Sub Main Dim MyModel As Model Dim MyDiagram As Diagram Dim MyEntity As Entity Dim NewName As String Dim MyIndex As Index ' set ER variables Set MyDiagram = DiagramManager.ActiveDiagram Set MyModel = MyDiagram.ActiveModel Begin Dialog UserDialog 310,196,"PK Naming Macro" ' %GRID:10,7,1,1 Text 50,14,210,28,"Choose Prefix, Suffix or Default (default is PK_)",.Text1 OKButton 30,154,110,21 CancelButton 180,154,110,21 OptionGroup .namingconvention OptionButton 50,56,90,14,"Default",.default OptionButton 50,77,110,14,"Prefix",.prefixorsuffix OptionButton 50,98,90,14,"Suffix",.OptionButton1 TextBox 160,119,110,21,.Prefix Text 50,126,90,14,"Prefix/Suffix:",.Text2 End Dialog Dim dlg As UserDialog If Dialog(dlg) = -1 Then 'loop through all entities For Each MyEntity In MyModel.Entities For Each MyIndex In MyEntity.Indexes ' make sure index/constraint is a primary key If MyIndex.IsPK = True Then ' use naming convention specified in the dialog If dlg.namingconvention = 0 Then MyIndex.Name = "PK_" + MyEntity.TableName ElseIf dlg.namingconvention = 1 Then MyIndex.Name = dlg.prefix & MyEntity.TableName Else MyIndex.Name = MyEntity.TableName & dlg.prefix End If End If Next MyIndex Next MyEntity End If End Sub