Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Finding all the tables a field exist in

Author  Topic 

sross81
Posting Yak Master

228 Posts

Posted - 2008-10-07 : 15:57:34
Hello,

I have 2,573 tables and I want to know out of all of these tables which ones contain a field called person_id. Is this something that is possible? I can't even think of where to start with the select statement. Any ideas would be greatly appreciated.



Thanks in Advance!
Sherri

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-07 : 16:00:02
See this:

http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-07 : 16:19:34
I wouldn't bother with the link that sodeep posted when you can do this easily like this:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'person_id'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sross81
Posting Yak Master

228 Posts

Posted - 2008-10-07 : 16:26:20
Wow the information schema is really helpful! I had never had to use that before but I was able to link a few of those views together and get exactly what I needed. Thanks for your help.

quote:
Originally posted by tkizer

I wouldn't bother with the link that sodeep posted when you can do this easily like this:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'person_id'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog




Thanks in Advance!
Sherri
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-07 : 17:03:01
quote:
Originally posted by tkizer

I wouldn't bother with the link that sodeep posted when you can do this easily like this:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'person_id'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



Yah. Forgot to read carefully the requirement before posting. Actually that link will provide columnname while you provide any value that exists Which is not required for you.

Go to Top of Page
   

- Advertisement -