Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Querying Path through Schema

Status
Not open for further replies.

hwkranger

MIS
Nov 6, 2002
717
US
Assuming that the Schema of my database is normalized and complete.. I would like to be able to do the following:

query sysobjects or a sysview that when given the name of 2 tables would return all tables between the two tables via relationships. (I only want tables that are between the two entities... anything NOT on the critical path should not be included)

I know there has to be a way to do this, but my brain isn't working this morning.

Thanks for the help.... (If I figure this out in the interum before someone else, I'll post it -- I'm sure this wuold be helpful to the community)

Randall Vollen
National City Bank Corp.
 
What version of SQL are you using? The system tables & views have slightly different names between 2000 and 2005.



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
I'm using 2000, but -- eventually this should be ported to 2005.

Thank you.

(I didn't get a chance to work so much on this today, since I got tasked to looking at some nasty projection models.)

Randall Vollen
National City Bank Corp.
 
You'll want to play with this, but it should give you what you want. Type U means User table.

Code:
Select so.name, so.Type, so1.name as DepName, sd.*
from sysobjects so
left outer join sysdepends sd
on so.ID = sd.ID
left outer join sysobjects so1
on sd.depID = so1.ID
where so.Type = 'U'
and so1.Type = 'U'
and so.Name = 'MyTable'



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top