Search for text within columns, tables, store procedures, and jobs in SQL 2008

Search the information_schema for columns, tables, stored procedures, and jobs by name:

–Query to list stored procedures that match a pattern
select ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_DEFINITION from INFORMATION_SCHEMA.ROUTINES
where ROUTINE_TYPE=‘PROCEDURE’ and ROUTINE_NAME like ‘%fabric%’
GO

–Query to list column names that match a pattern – lists table information
select * from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME like ‘%fabric%’
GO 

–Query to list table names that match a pattern
select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME like ‘%fabric%’
GO 

–Query within a job
USE [msdb]
GO
SELECT j.job_id,  s.srvname,  j.name,  js.step_id,  js.command, j.enabled
FROM dbo.sysjobs j
JOIN dbo.sysjobsteps js ON js.job_id = j.job_id
JOIN master.dbo.sysservers s ON s.srvid = j.originating_server_id
WHERE js.command LIKE N’%fabric%’
GO

 

Leave a Reply