Indexes, Primary Keys and Relationships in MS Access

N

Naveen

Hi,

How can i query/get the following in an MS Access 2002
Database: -

1. List of Indexed Fields in the MDB
2. All the Primary Key Fields in the MDB
3. List of Constraints/Foreign Key relationships in the MDB

Is there some way to query this information instead of
going table by table in the design view?

Thanks!
 
A

Allen Browne

You can access these things programmatically.

This example lists the names of the relationships in the current database,
including the table and foreign table. Each relation has other properties as
well.

Function ShowRel()
Dim db As DAO.Database
Dim rel As DAO.Relation

Set db = CurrentDb()
For Each rel In db.Relations
Debug.Print rel.Name, rel.Table, rel.ForeignTable
Next

Set rel = Nothing
Set db = Nothing
End Function
 
N

Naveen

Thanks! This works.

I was curious to know if there was some way to query the
MDB and get the information instead of coding.

Thank you,
 
A

Allen Browne

This is undocumented, but may help:

SELECT MSysRelationships.* FROM MSysRelationships;
 
N

Naveen

Thanks!
-----Original Message-----
This is undocumented, but may help:

SELECT MSysRelationships.* FROM MSysRelationships;

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top