您的位置:首页 > 数据库

SQL - 查找 过程、函数、触发器 是否包含 某个指定 字符串

2011-01-28 11:59 453 查看
如何查找自己写的sql server 哪些存储过程,函数、触发器包含某个指定的字符串 ?

1.查找 过程、函数 代码里是否包含指定的串:

SELECT ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%搜索的字符串%'

-------------------------------------------------------------------------------------------------------------

2.查找 触发器 代码里是否包含指定的串:

set nocount on
Create table #y (Trname varchar(50),txt text)
select name, iid = identity(int,1,1) into #x from SysObjects where xtype = 'TR'
declare @i int, @max int
declare @name varchar(50)
set @i = 1
select @max = max(iid) from #x
while @i <= @max
begin
select @name = name from #x where iid = @i
insert #y (txt)
exec('sp_helptext ' + @name)

update #y
set Trname=@name
where Trname is null
set @i = @i + 1
end
select * from #y where txt LIKE '%搜索的字符串%'
drop table #x
drop table #y
set nocount off
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐