foreign key information

  • how could i know or collect foreign key in my database

  • Look up sp_fkeys in BOL (Books Online)

    This will produce sql to find foreign keys in current database

    SELECT 'exec sp_fkeys '+name FROM sysobjects WHERE type = 'u'

    copy and paste results into another QA windows and execute

     

    Far away is close at hand in the images of elsewhere.
    Anon.

  • There are also system table views provided by Microsoft that can provide foreign key information. They are:

    information_schema.constraint_table_usage

    information_schema.constraint_column_usage

    information_schema.table_constraints

    You query them as you would any other table or view except you must qualify them and you can access them from any database:

    select * from information_schema.constraint_table_usage

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply