All columns along with flag for foreign key or not

  • Hi

    I need list of all columns in the database along with a flag or what ever which should indicate whether it is a key(foreign key) or not. Can any one please help on this

    /********************************************************
    Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
    ********************************************************/

  • Hello,

    You could probably build a formatted report using this code snippet as the starting point:-

    Select

    *

    From

    sys.columns SC

    Left Join sys.foreign_key_columns FKC

    On (FKC.parent_object_id = SC.object_id) And (FKC.parent_column_id = SC.column_id)

    Regards,

    John Marsh

    www.sql.lu
    SQL Server Luxembourg User Group

  • Thanq john actually i am sarching for any buit in function or view for this any ways thnq for the reply

    /********************************************************
    Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
    ********************************************************/

  • grngarlapati (3/7/2009)


    Thanq john actually i am sarching for any buit in function or view for this any ways thnq for the reply

    The views that John used in his query are built-in system views. There's no view of function that, by itself, will give you what you want, you'll have to build a query up using sys.columns and sys.foreign_key_columns.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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