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 |
|
phrankbooth
Posting Yak Master
162 Posts |
Posted - 2012-05-22 : 21:23:09
|
| Using MS SQL 2008 R2:I'd like to list table names for a DB in the WHERE clause, something along these lines:Select TableNameFrom <sys view or infoschema join or something>WHERE DBName = 'dbname'Been looking all over and haven't found it.Thanks!--PhB |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-22 : 21:27:02
|
either thisselect *from dbname.INFORMATION_SCHEMA.TABLES ORselect *from dbname.sys.tables if you must pass in the dbname as a parameter, you will need to use Dynamic SQL KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
phrankbooth
Posting Yak Master
162 Posts |
Posted - 2012-05-22 : 21:31:41
|
| Ah got it!! Thanks for the quick reply!--PhB |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-23 : 15:59:20
|
quote: Originally posted by khtan either thisselect *from dbname.INFORMATION_SCHEMA.TABLES ORselect *from dbname.sys.tables if you must pass in the dbname as a parameter, you will need to use Dynamic SQL KH[spoiler]Time is always against us[/spoiler]
Please keep in mind this will also return views so if you want to return only tables use additional condition likeselect *from dbname.INFORMATION_SCHEMA.TABLESWHERE TABLE_TYPE = 'BASE TABLE' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|