views:

35

answers:

3

What is an easy way to list the foreign key contraints in an MDB?

Is there a system table that can be queried in order to list this information?

Specifically, I need to know whether any foreign key contraints exist in the MDB.

A: 

Open up Relationships window (Tools > Relationships or use the Relationships toolbar button). In that window, right click > click "Show All". This adds all tables to the window and all relationships are represented by lines/arrows.

Salman A
A: 

Take a look at the results of select * from MSysRelationships.

Alex K.
How do I get read permissions for this table?
Craig Johnston
You should be able to select it directly in a new query
Alex K.
The response from the query is that I don't have read permissions.
Craig Johnston
A: 

Or you can examine the relationships collection of the database object:

  Public Sub PrintRelationships()
    Dim varItem As Variant
    Dim varItem2 As Variant

    For Each varItem In CurrentDb.Relations
      Debug.Print varItem.Name
      Debug.Print " " & varItem.Table
      Debug.Print " " & varItem.ForeignTable
      For Each varItem2 In varItem.Fields
        Debug.Print ": " & varItem2.Name
      Next varItem2
    Next varItem
  End Sub

There are other properties that might be of interest. Also, an MS Knowledge Base article on copying relationships may give you some ideas.

David-W-Fenton