標籤:
Use 資料庫
DECLARE @ProcName varchar(50)
Create Table #tmpName(Content varchar(2000))
Create Table #tmp(ProcName varchar(2000),Content1 varchar(8000))
--定義一個遊標
DECLARE SearchProc CURSOR FOR
--查詢資料庫中預存程序的名稱,盡量去除系統PROC,可以根據crdate時間欄位來尋找非系統PROC
select name from sysobjects where type=‘P‘ and name not like ‘dt_%‘
OPEN SearchProc
FETCH NEXT FROM SearchProc
INTO @ProcName
WHILE @@FETCH_STATUS >=0
BEGIN
Print @ProcName
Insert Into #tmpName(Content) Exec sp_helptext @ProcName
Insert Into #tmp(ProcName,Content1) select @ProcName,#tmpName.Content from #tmpName
--填充完就清空一下暫存資料表
Truncate table #tmpName
FETCH NEXT FROM SearchProc
INTO @ProcName
END
CLOSE SearchProc
DEALLOCATE SearchProc
GO
select ProcName from #tmp where Content1 like ‘%尋找內容%‘ group by ProcName
select ProcName,Content1 from #tmp where Content1 like ‘%尋找內容%‘
select ProcName,Content1 from #tmp where procname=‘預存程序名稱‘
--刪除暫存資料表
Drop Table #tmpName
Drop Table #tmp
利用SQL語句尋找某資料庫中所有預存程序包含的內容(轉)