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

x
?
Solved

List foreign keys for a specified table

Posted on 2009-02-10
2
Medium Priority
?
306 Views
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.
0
Comment
Question by:JRockFL
2 Comments
 
LVL 39

Accepted Solution

by:
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')
0
 
LVL 8

Expert Comment

by:OBonio
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....

0

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