Search All Tables

  • Okay, there has to be a better way to to what I want to accomplish, I just can't figure it out. I want to search all my tables in the database and then tell me which one has a column name = Compkey and that Compkey is = 270188. I wrote the following script:

    select 'SELECT * FROM' + ' ' + TABLE_SCHEMA+'.'+ TABLE_NAME + ' WHERE ' + COLUMN_NAME + '=''270188''' --ENTER COMPKEY HERE

    from INFORMATION_SCHEMA.COLUMNS

    where COLUMN_NAME = 'COMPKEY'

    order by TABLE_SCHEMA

    This works, the only problem is I then get 411 queries that I need to run to find the tables that has compkey = 270188. Any suggestions here?

    Thanks!!!

    Jordon

  • Sorry! Meant to post this in the T-SQL forum!

  • No replies to this thread please. Direct replies to:http://www.sqlservercentral.com/Forums/Topic1384236-392-1.aspx

    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 3 posts - 1 through 2 (of 2 total)

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