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.
| Author |
Topic |
|
qingchengottawa
Starting Member
7 Posts |
Posted - 2006-10-12 : 09:40:08
|
| I would like to search a column name in all the tables in a database. Is there a way to do it?Thanks,Qing |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-10-12 : 09:42:33
|
| [code]SELECT table_name, column_nameFROM dbname.information_schema.columnsWHERE column_name LIKE '%searchterm%'[/code]--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-12 : 09:42:50
|
| Yes. You can create a view and union all tables or you can turn to dynamic sql.There are a lot of topics for that here at SQLTeam. Feel free to search.Peter LarssonHelsingborg, Sweden |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-10-12 : 09:50:39
|
Ah...I was so fascinated by the information_schema views that I thought that was what he was looking for --Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-13 : 10:16:41
|
quote: Originally posted by Peso Yes. You can create a view and union all tables or you can turn to dynamic sql.There are a lot of topics for that here at SQLTeam. Feel free to search.Peter LarssonHelsingborg, Sweden
Did you mean searching a value in all columns of all tables?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|