SSMS
 sql >> Datenbank >  >> Database Tools >> SSMS

SQL Server Management Studio – Suchen Sie gespeicherte Prozeduren anhand des Namens über mehrere Datenbanken hinweg

Sie können dynamisches SQL verwenden, um die Prozedur über alle Datenbanken in SQL Server Management Studio zu überprüfen

USE MASTER
GO
BEGIN TRAN

DECLARE @strt INT,@End INT,@Database NVARCHAR(50)

SELECT * INTO #T FROM Sys.databases WITH(NOLOCK) WHERE database_id>4 
ORDER BY 1

SELECT ROW_NUMBER ()OVER (ORDER BY database_Id)Db_Id,* INTO #TT FROM #T
SET @strt=1
SELECT @End=Max(Db_ID)FROM #tt

WHILE @strt<[email protected]
     BEGIN
         DECLARE @string NVARCHAR(MAX)
         SELECT @Database=NAME FROM #TT WHERE [email protected]

        Set @string='  Select '''[email protected]+'''db_Name,* from '[email protected]+'.sys.objects 
          WHERE Name=''XYZ_procedure'''

          SET @[email protected]+1
          PRINT @string
          EXEC(@string)
     END

ROLLBACK TRAN