SQL Server SQL Server 查询数据库中所有存储过程和触发器

xinggang · 2018年05月05日 · 65 次阅读

统计一下:

select t.sp_name, sum(t.lines_of_code) - 1 as lines_ofcode, t.type_desc
from
(
select o.name as sp_name,
(len(c.text) - len(replace(c.text, char(10), ''))) as lines_of_code,
case when o.xtype = 'P' then '存储过程'
when o.xtype in ('FN', 'IF', 'TF') then '函数' when o.xtype='TR' then '触发器'
end as type_desc
from sysobjects o
inner join syscomments c
on c.id = o.id
where o.xtype in ('P','TR','FN', 'IF', 'TF')
and o.category = 0
and o.name like 'pzyz%'
) t
group by t.sp_name, t.type_desc
order by 1

结果:
20180505092538

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册