|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 11:19 AM
Points: 309,
Visits: 645
|
|
I have three tables and I need to find to which DB these tables belong. I am not sure how to do this. There are 29 DBs and to do task manually is a really bad idea.
I used sp_help 'tablename' -- No use select * from sysobjects where name = 'tablename' --No use
-LK
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Saturday, March 02, 2013 4:42 AM
Points: 525,
Visits: 1,096
|
|
google for sp_Msforeachdb. It will definitely help you.
Thanks Chandra Mohan
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 11:19 AM
Points: 309,
Visits: 645
|
|
Following is my learning today. MS_Foreachtable can execute more than one command simultaneously.
exec sp_MSforeachtable 'select ''?'', count(1) from ?'
exec sp_MSforeachtable "print '?' DBCC DBREINDEX('?')"
exec sp_MSforeachtable "print '?' SELECT count(1) from ? SELECT TOP 1* FROM ?"
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, April 16, 2013 12:26 PM
Points: 185,
Visits: 725
|
|
luckysql.kinda (7/22/2009) I have three tables and I need to find to which DB these tables belong. I am not sure how to do this. There are 29 DBs and to do task manually is a really bad idea.
I used sp_help 'tablename' -- No use select * from sysobjects where name = 'tablename' --No use
-LK
Hey This works for you
exec sp_MSforeachdb " print '?' select name from sys.sysobjects where name in ('Table1','Table2','Table3')"
Rajesh Kasturi
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 11:42 AM
Points: 1,654,
Visits: 8,563
|
|
exec sp_MSforeachdb "select '?' As DatabaseName,name from ?.dbo.sysobjects where name in ('Tablename')"
MJ
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, April 16, 2013 12:26 PM
Points: 185,
Visits: 725
|
|
MANU (7/24/2009) exec sp_MSforeachdb "select '?' As DatabaseName,name from ?.dbo.sysobjects where name in ('Tablename')"
MJ
hey manu
thanks for modifying the query........
cheers.......
Rajesh Kasturi
|
|
|
|