Sunday, October 9, 2016

Search for a Specific String in a SQL Server Database


Search for a string throughout SQL Server database.

Declare @SEARCHSTRING VARCHAR(255)

SELECT
    @SEARCHSTRING = 'YOUR_SEARCH_STRING'

SELECT DISTINCT sysobjects.name AS [Object Name] ,
case when sysobjects.xtype = 'P' then 'Stored Proc'
when sysobjects.xtype in ('FN', 'TF') then 'Function'
when sysobjects.xtype = 'TR' then 'Trigger'
when sysobjects.xtype = 'V' then 'View'
end as [Object Type], sysobjects.xtype
FROM sysobjects,syscomments
WHERE sysobjects.id = syscomments.id
--AND sysobjects.type in ('P','TF','TR','V','FN')
AND sysobjects.category = 0
AND CHARINDEX(@SEARCHSTRING,syscomments.text)>0
Query finds all the database objects which contain a specific string (which you assign to @SEARCHSTRING variable)

No comments:
Write comments
Recommended Posts × +