November 13, 2012 at 11:57 am
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
November 13, 2012 at 11:58 am
Sorry! Meant to post this in the T-SQL forum!
November 13, 2012 at 12:36 pm
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
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply