שלום רב,
להלן פרוצדורה שימושית אשר מקבלת סטרינג ומחפש את הערך הנ"ל בכל הפרוצדורות בכל בסיסי הנתונים .
CREATE PROCEDURE Find_Text_In_SP_InAllTables
@mysting nvarchar(250)
as
DECLARE @sqlCommand nvarchar(max)
CREATE TABLE #TABLE (DATABASENAME nvarchar(250) , PROCEDURE_NAME nvarchar(max))
DECLARE @unique_num nvarchar(250)
set @mysting = '''%' + @mysting + '%'''
DECLARE uniques_cursor CURSOR FOR
select name
from sys.databases
OPEN uniques_cursor
FETCH NEXT
FROM uniques_cursor
INTO @unique_num
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sqlCommand = 'INSERT INTO #TABLE select ''' +@unique_num + ''' ,definition from '+@unique_num +'.sys.sql_modules where definition like '+@mysting
EXECUTE sp_executesql @sqlCommand
FETCH NEXT
FROM uniques_cursor
INTO @unique_num
END
CLOSE uniques_cursor
DEALLOCATE uniques_cursor
select * from #TABLE
drop TABLE #TABLE
GO
@mysting nvarchar(250)
as
DECLARE @sqlCommand nvarchar(max)
CREATE TABLE #TABLE (DATABASENAME nvarchar(250) , PROCEDURE_NAME nvarchar(max))
DECLARE @unique_num nvarchar(250)
set @mysting = '''%' + @mysting + '%'''
DECLARE uniques_cursor CURSOR FOR
select name
from sys.databases
OPEN uniques_cursor
FETCH NEXT
FROM uniques_cursor
INTO @unique_num
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sqlCommand = 'INSERT INTO #TABLE select ''' +@unique_num + ''' ,definition from '+@unique_num +'.sys.sql_modules where definition like '+@mysting
EXECUTE sp_executesql @sqlCommand
FETCH NEXT
FROM uniques_cursor
INTO @unique_num
END
CLOSE uniques_cursor
DEALLOCATE uniques_cursor
select * from #TABLE
drop TABLE #TABLE
GO
על מנת להריץ את הפרוצדורה:
exec Find_Text_In_SP_InAllTables 'Batch'
אין תגובות:
הוסף רשומת תגובה