Answered Remove an Orphaned Relationship from Database model

  • Friday, May 20, 2011 10:54 AM
     
     

    Hi,

    I have a database model in Visio for Enterprise Architects 2003.

    I have managed to remove a relationship link from the diagram but not the relationship from the underlying model. I am now unable to remove that relationship from the model itself, and so the database will not validate.

    There would appear to be no way to do this.

    Can anyone put me out of my misery and tell me how I can get rid of this relationship from the model without deleting one of the tables and recreating it?

     

    Thankyou

     

    Paul

Answers

  • Monday, May 23, 2011 9:09 AM
    Moderator
     
     Answered

    Hi Paul,

    Try the code below provide by Chang Oh from Microsoft.

    ' This is provided "AS IS" with no warranties, and
    ' confers no rights.
    '
    ' This module removes all relationships that are NOT fully connected
    ' to either parent table or child table. The relationship may or may
    ' not visible. If you get
    ' filename : error L2100: FK name : Relationship is not fully connected.
    ' error messages and not able to locate it on the diagram, then this module
    ' will remove the relationships from the model.
    '
    ' Follow the following steps
    '
    ' Select "Tools"/"Macros"/"Visual Basic Editor" from the Visio menus.
    ' Select "Tools"/"References" from the Visual Basic editor.
    ' Check "Microsoft Visio Database Modeling Engine Type Library" and
    ' click the OK button.
    ' Copy this following subroutine into the text area under "(General)"
    ' Select "Run"/"Run Sub-UserForm" (or hit the play button)
    ' Close the Visual Basic editor
    ' Now select "Database"/"Model"/"Error Check"
    '
    Sub DeleteAllDisconnectedRelationshipsFromAllModels()

    Dim vme As New VisioModelingEngine
    Dim models As IEnumIVMEModels
    Dim model As IVMEModel
    Dim elements As IEnumIVMEModelElements
    Dim element As IVMEModelElement
    Dim relationship As IVMERelationship

    Set models = vme.models
    Set model = models.Next

    Do While Not model Is Nothing
    Set elements = model.elements
    Set element = elements.Next

    Do While Not element Is Nothing
    If (element.Type = eVMEKindERRelationship) Then
    Set relationship = element

    If (Not relationship.IsFullyConnected) Then
    model.DeleteElement element.ElementID
    Set elements = model.elements
    End If
    End If

    Set element = elements.Next
    Loop

    Set model = models.Next
    Loop
    End Sub


    Sincerely,
    Max Meng


    Come back and mark the replies as answers if they help and unmark them if they provide no help.

All Replies

  • Monday, May 23, 2011 9:09 AM
    Moderator
     
     Answered

    Hi Paul,

    Try the code below provide by Chang Oh from Microsoft.

    ' This is provided "AS IS" with no warranties, and
    ' confers no rights.
    '
    ' This module removes all relationships that are NOT fully connected
    ' to either parent table or child table. The relationship may or may
    ' not visible. If you get
    ' filename : error L2100: FK name : Relationship is not fully connected.
    ' error messages and not able to locate it on the diagram, then this module
    ' will remove the relationships from the model.
    '
    ' Follow the following steps
    '
    ' Select "Tools"/"Macros"/"Visual Basic Editor" from the Visio menus.
    ' Select "Tools"/"References" from the Visual Basic editor.
    ' Check "Microsoft Visio Database Modeling Engine Type Library" and
    ' click the OK button.
    ' Copy this following subroutine into the text area under "(General)"
    ' Select "Run"/"Run Sub-UserForm" (or hit the play button)
    ' Close the Visual Basic editor
    ' Now select "Database"/"Model"/"Error Check"
    '
    Sub DeleteAllDisconnectedRelationshipsFromAllModels()

    Dim vme As New VisioModelingEngine
    Dim models As IEnumIVMEModels
    Dim model As IVMEModel
    Dim elements As IEnumIVMEModelElements
    Dim element As IVMEModelElement
    Dim relationship As IVMERelationship

    Set models = vme.models
    Set model = models.Next

    Do While Not model Is Nothing
    Set elements = model.elements
    Set element = elements.Next

    Do While Not element Is Nothing
    If (element.Type = eVMEKindERRelationship) Then
    Set relationship = element

    If (Not relationship.IsFullyConnected) Then
    model.DeleteElement element.ElementID
    Set elements = model.elements
    End If
    End If

    Set element = elements.Next
    Loop

    Set model = models.Next
    Loop
    End Sub


    Sincerely,
    Max Meng


    Come back and mark the replies as answers if they help and unmark them if they provide no help.
  • Thursday, October 06, 2011 11:40 PM
     
     
    Terrific. I was having this same problem and this little bit of VB code worked great. Thanks.