Click here to Skip to main content
15,888,124 members
Articles / Database Development
Alternative
Tip/Trick

How to find a specific string from stored procedures, triggers and functions in database

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
7 Feb 2012CPOL 6.5K   1  
Simply add your search phrase and run to find jobs, Stored Procedures, Keys, Tables, Views, Indexes, Defaults, and Functions.set nocount on declare @Keyword as varchar(200)set @Keyword = 'Search prase'--<---- enter keyword here--Search jobsselect name Job, enabled , description, ...

Simply add your search phrase and run to find jobs, Stored Procedures, Keys, Tables, Views, Indexes, Defaults, and Functions.


SQL
set nocount on 
declare @Keyword as varchar(200)
set @Keyword = 'Search prase'--<---- enter keyword here

--Search jobs
select name Job, enabled , description,  date_created, date_modified ,step_id,  step_name ,subsystem,
	command, last_run_date
	from msdb.dbo.sysjobs j with (nolock)
	join msdb.dbo.sysjobsteps s on j.job_id = s.job_id
	where command like'%'+ @Keyword +'%'

/*
Search: 
stored procedures
Keys
Tables
Views
Indexes
Defaults
Functions
*/

SELECT DISTINCT
	name, 
	CASE o.xtype 
		WHEN 'S' THEN 'System Stored Proc'
		WHEN 'F' THEN 'Foreign Key'
		WHEN 'U' THEN 'Table'
		WHEN 'V' THEN 'View'
		WHEN 'P' THEN 'Stored Proc'
		WHEN 'PK' THEN 'Primary Key'
		WHEN 'TR' THEN 'Trigger'
		WHEN 'UQ' THEN 'Unique Index'
		WHEN 'D' THEN 'Default'
		WHEN 'FN' THEN 'User Defined Function'
		ELSE 'Unknown'
	END, 
	text 
FROM
	sysobjects o left join syscomments c ON c.id = o.id
WHERE
	text LIKE '%' + @Keyword + '%' 
OR	name LIKE '%' + @Keyword + '%'

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --