Мой коллега любезно предоставил мне это недавно.Он выполняет поиск, подобный тому, который отмечали другие, но с добавлением немного больше.
DECLARE
@chvStringToFind varchar(256), /* String to find */
@chrObjectType char(2),--=null, /* Only look for objects of this type */
@intNbCharToExtract int
--=50 /* Number of characters to extract before and after the string to find */
--exec DBA_FindStringInDB @chvStringToFind='sp_helpdia', @chrObjectType=null, @intNbCharToExtract=50
SET @chvStringToFind = 'EnterSearchTextHere' -- Change this to search
SET @chrObjectType = NULL
SET @intNbCharToExtract = 50
SELECT t.Name, t.TypeDescription, t.CreationDate, t.ModificationDate,
'...' + SUBSTRING
(
t.ObjectDefinition,
CHARINDEX(@chvStringToFind, t.ObjectDefinition) - @intNbCharToExtract,
LEN(@chvStringToFind) + (@intNbCharToExtract*2)
) + '...' AS Extract
FROM
(
SELECT o.name AS Name,
o.type_desc AS TypeDescription,
o.create_date AS CreationDate, o.modify_date AS ModificationDate,
OBJECT_DEFINITION(object_id) AS ObjectDefinition
FROM sys.objects o
WHERE
((o.type IN ('AF', 'FN', 'IF', 'P', 'TF', 'TT', 'U', 'V', 'X') AND @chrObjectType IS NULL) OR o.type = @chrObjectType)
AND OBJECT_DEFINITION(o.object_id) LIKE '%' + @chvStringToFind + '%'
) AS t
ORDER BY TypeDescription, Name