Searching a particular table in DB

  • Hi All,

    I have list of columns (say col1,col2,col3). I need to find the table in the database which contains these 3 columns. Please suggest.

    Regards

    Jim

  • You can query the sys.columns metadata view to see what tables have particular columns in them.

    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
  • select * from information_schema.columns

    where column_name like '%col1%'

    OR column_name like '%col2%' OR column_name like '%col3%'

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • SELECT

    OBJECT_NAME(object_id) AS table_name

    FROM sys.columns

    WHERE

    name IN ( 'col1', 'col2', 'col3' ) AND

    OBJECTPROPERTYEX (object_id, 'BaseType') IN ( 'U', 'V' )

    GROUP BY

    object_id

    HAVING

    COUNT(*) = 3

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

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

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