ACC1x: How to List Related Tables in a Database in Version 1.xID: Q88653
|
Although you can create relationships among tables in your database, there
is no inherent Microsoft Access command to gather this information and
present it in a meaningful way. Sometimes this information can be helpful,
for instance, to find the source table of a referential integrity
violation. This article discusses how you can use a series of queries to
gather and relate information you need from the system tables MSysObjects,
MSysColumns, and MSysIndexes.
To gather information and present it in a meaningful way, you can create a
query containing two columns. The first column, called Primary.Name, will
contain a table name. The second column, called Foreign.Name, will
represent the table that the Primary.Name table is related to.
Because the information will be coming from the system tables mentioned
above, you must make sure you have access rights to these tables.
MSysObjects has these rights by default. To give yourself access rights to
MSysIndexes and MSysColumns, follow these steps:
SELECT DISTINCTROW
MSysObjects.Name, MSysObjects.Id
FROM MSysObjects
WHERE ((MSysObjects.Type=1)
AND (MSysObjects.Flags Is Null Or MSysObjects.Flags<>2))
ORDER BY MSysObjects.Name;
SELECT DISTINCTROW [Tables].Name AS Table,
MSysColumns.Name AS Field,
[Tables].Id AS [Primary Id]
FROM [psi User Tables] AS Tables, MSysColumns, Tables
INNER JOIN MSysColumns ON [Tables].Id = MSysColumns.ObjectId
ORDER BY [Tables].Name, MSysColumns.PresentationOrder;
SELECT DISTINCTROW Primary.Name, Foreign.Name
FROM [psi User Tables] AS Primary, MSysIndexes, [psi User Tables]
AS Foreign, MSysIndexes AS LKeyName, LKeyName
INNER JOIN MSysIndexes ON LKeyName.Idxid = MSysIndexes.Idxid,
LKeyName
INNER JOIN MSysIndexes ON LKeyName.ObjectId = MSysIndexes.ObjectId,
Primary
INNER JOIN MSysIndexes ON Primary.Id = MSysIndexes.ObjectId,
Foreign INNER JOIN MSysIndexes ON Foreign.Id =
MSysIndexes.ObjectIdReference
WHERE ((MSysIndexes.ObjectIdReference<>0)
AND (MSysIndexes.Operation=2)
AND (LKeyName.Operation=0))
ORDER BY Primary.Name, Foreign.Name;
Keywords : kbusage RltOthr
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: March 10, 1999