SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


to which DB these tables belong


to which DB these tables belong

Author
Message
luckysql.kinda
luckysql.kinda
Right there with Babe
Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)

Group: General Forum Members
Points: 728 Visits: 659
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
Chand00
Chand00
Right there with Babe
Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)

Group: General Forum Members
Points: 776 Visits: 1257
google for sp_Msforeachdb. It will definitely help you.

Thanks
Chandra Mohan

luckysql.kinda
luckysql.kinda
Right there with Babe
Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)

Group: General Forum Members
Points: 728 Visits: 659
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 ?"
Rajesh kasturi
Rajesh kasturi
Old Hand
Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)

Group: General Forum Members
Points: 353 Visits: 732
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
MANU-J.
MANU-J.
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2986 Visits: 8766
exec sp_MSforeachdb "select '?' As DatabaseName,name from ?.dbo.sysobjects where name in ('Tablename')"


MJ
Rajesh kasturi
Rajesh kasturi
Old Hand
Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)

Group: General Forum Members
Points: 353 Visits: 732
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search