20 October 2008

I m using SQL Server 2005 and trying to get table name "myTable" from all databases from SQL Server

begin try
Exec sp_MSforeachdb 'Select * From ?..sysobjects where name=''myTable'''
end try
begin catch
print 'error'
end catch

1 comment :

  1. Modifying the Exec sp_MSforeachdb statement to

    Exec sp_MSforeachdb 'Select ''[?]'',* From ?..sysobjects where name=''ProductPlacementSet'''

    will display the Database name along with the additional sysobjects data.

    ReplyDelete