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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listink Foreign Key Linkings

Status
Not open for further replies.

mutley1

MIS
Jul 24, 2003
909
Hi All,

SQL 2000.

We are looking to redesign a bit od a bodge job of an old database which has about 700 od tables in it, and my question is such. Is there an easy way to list tables, PK's FK's (that's the easy bit which I can do), but id the FK is linked to ANOther table, to show that linking as well (i.e. under relationships tab of table design / manage keys).

Cheers,

M.
 
I think this is what you're looking for. Not the most optimized query, but it gets the job done.

Code:
select name as ForeignKey, 
(select name from sys.objects o where fk.parent_object_id=o.object_id) as ParentTable,
(select name from sys.objects o where fk.referenced_object_id=o.object_id) as ReferencedTable
 from sys.foreign_keys fk
order by name asc

-If it ain't broke, break it and make it better.
 
Oops, just saw that you're looking at SQL 2000. My query is for 2005.

-If it ain't broke, break it and make it better.
 
No worries Mich, thanks for reading the post though!

Appreciated,

M.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top