List foreign keys for a specified table

Posted on 2009-02-10
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

    SQL 2000

    select from sysobjects o
    join sysobjects ro
    join sysreferences r
    where object_id('YOURTABLENAME')
    LVL 8

    Expert Comment

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now