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

故事扮演 提交于 2019-12-01 21:01:48

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

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.

Dim rs As ADODB.Recordset
Set rs = oConn.OpenSchema(adSchemaForeignKeys)

where oConn is ADODB.connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!