/*
name: trigger, procedure, view, function name
xtype: TR = trigger, P = procedure, V = view, FN = function
*/
Declare @SearchKey nvarchar(200)
Set @SearchKey='BU'
if @SearchKey=''
begin
print 'Error! Please input search word!'
return
end
print 'Search Keyword is:'+@SearchKey
SELECT DISTINCT B.NAME Result,
CASE B.XTYPE WHEN 'TR' THEN '触发器' WHEN 'P' THEN '存储过程' WHEN 'V' THEN '视图' WHEN 'FN' THEN '函数' END XTYPENAME
FROM SYSCOMMENTS A, SYSOBJECTS B
WHERE A.TEXT LIKE '%'+@SearchKey+'%' AND B.ID=A.ID AND B.STATUS>=0 AND
(B.XTYPE='P' OR B.XTYPE='TR' OR B.XTYPE='V' OR B.XTYPE='FN')