Use SQL statements to find what is contained in all stored procedures in a database (GO)

Source: Internet
Author: User

Use database
DECLARE @ProcName varchar (50)
Create Table #tmpName (Content varchar (2000))
Create Table #tmp (procname varchar, Content1 varchar (8000))
--Define a cursor
DECLARE Searchproc CURSOR for
--Query the name of the stored procedure in the database, as far as possible to remove the system proc, can be based on the Crdate time field to find non-system proc
Select name from sysobjects where type= ' P ' and name is not a 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 the. Content from #tmpName
--Empty the temp table when you're done filling it up
Truncate Table #tmpName
FETCH NEXT from Searchproc
Into @ProcName
END
CLOSE Searchproc
Deallocate Searchproc
GO

Select ProcName from #tmp where Content1 like '% find content% ' GROUP by procname

Select Procname,content1 from #tmp where Content1 like '% find content% '

Select Procname,content1 from #tmp where procname= ' stored procedure name '
--Delete temporary tables
Drop Table #tmpName
Drop Table #tmp

Use SQL statements to find what is contained in all stored procedures in a database (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.