March 11, 2016 at 11:26 am
I was given this SQl statement. Could not find a table like that. We have about 25 databses in our SQl server. Is there a script that I can write to search all the databases in the server ? ( to see which db holds this table )
SELECT DISTINCT ReptMonth, StartChkDt
FROM ClmRejRept
ORDER BY StartChkDt DESC
March 11, 2016 at 11:41 am
this will work:
if the database name shows up, it has a table with that name:
exec sp_MSforeachdb 'SELECT ''?'' As DatabaseName FROM [?].sys.tables WHERE name = ''ClmRejRept'' '
Lowell
March 11, 2016 at 12:12 pm
Nice syntax...
I was just playing with the SQl and ran the following
exec sp_MSforeachdb 'SELECT top 1 ''?'' As DatabaseName FROM [?].sys.tables '
However it only listed about 6 of the databases. We have many more than that
March 11, 2016 at 12:39 pm
mw112009 (3/11/2016)
Nice syntax...I was just playing with the SQl and ran the following
exec sp_MSforeachdb 'SELECT top 1 ''?'' As DatabaseName FROM [?].sys.tables '
However it only listed about 6 of the databases. We have many more than that
if you are not sysadmin, you might be getting just the databases you(yourlogin) have access to.
could that be in?
Lowell
March 11, 2016 at 12:43 pm
Makes sense.! Thanks for the perfect answer
March 11, 2016 at 1:43 pm
I always do it like this:
DECLARE @command VARCHAR(1600)
SELECT @command = 'Use [' + '?' + ']
SELECT file_id,
name...
FROM sys.database_files'
EXEC sp_MSForEachDB @command
March 11, 2016 at 1:48 pm
Thx for the reply....
Jon.Morisi:
BTW More than your reply I was taken by the changing ICON you were using. That is cool!
May I wask what tool you used to create the animated GIF file.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply