[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


List foreign keys for a specified table

Posted on 2009-02-10
Medium Priority
Last Modified: 2012-05-06
I'm trying to list all of the foreign key relationships for a specified table.

I was thinking I could use
sp_fkeys 'enrollments' but this is not returning the desired results.
Question by:JRockFL
LVL 39

Accepted Solution

BrandonGalderisi earned 2000 total points
ID: 23603219
SQL 2000

select ro.name from sysobjects o
join sysobjects ro
on o.id=ro.parent_obj
join sysreferences r
on r.constid=ro.id
where o.id= object_id('YOURTABLENAME')

Expert Comment

ID: 23603257
Which version of SQL Server?  With 2005 you can use the Sys.foreign_keys table to link to Sys.objects, though I think you may need Sys.columns also as foreign keys apply to columns rather than tables....


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question