博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL Server查询数据库所有存储过程、触发器、索引信息SQL分享
阅读量:6374 次
发布时间:2019-06-23

本文共 3278 字,大约阅读时间需要 10 分钟。

  1. 查询所有存储过程

1 select Pr_Name as [存储过程], [参数]=stuff((select ','+[Parameter] 2 from ( 3 select Pr.Name as Pr_Name,parameter.name +' ' +Type.Name + ' ('+convert(varchar(32),parameter.max_length)+')' as Parameter 4 from sys.procedures Pr left join 5 sys.parameters parameter on Pr.object_id = parameter.object_id 6 inner join sys.types Type on parameter.system_type_id = Type.system_type_id 7 where type = 'P' 8 ) t where Pr_Name=tb.Pr_Name for xml path('')), 1, 1, '') 9 from (10 select Pr.Name as Pr_Name,parameter.name +' ' +Type.Name + ' ('+convert(varchar(32),parameter.max_length)+')' as Parameter11 from sys.procedures Pr left join12 sys.parameters parameter on Pr.object_id = parameter.object_id13 inner join sys.types Type on parameter.system_type_id = Type.system_type_id14 where type = 'P'15 )tb16 where Pr_Name not like 'sp_%' --and Pr_Name not like 'dt%'17 group by Pr_Name18 order by Pr_Name

  2. 存储过程信息查询

1 select Pr.Name as Pr_Name,parameter.name,T.Name,convert(varchar(32),parameter.max_length) as 参数长度,parameter.is_output as 是否是输出参数,parameter.*2 from sys.procedures Pr left join3 sys.parameters parameter on Pr.object_id = parameter.object_id4 inner join sys.types T on parameter.system_type_id = T.system_type_id5 where Pr.type = 'P' and Pr.Name like 'order_%' and T.name!='sysname' order by Pr.Name

  3. 查询所有触发器

1 select triggers.name as [触发器],tables.name as [表名],triggers.is_disabled as [是否禁用], 2 triggers.is_instead_of_trigger AS [触发器类型], 3 case when triggers.is_instead_of_trigger = 1 then 'INSTEAD OF' 4 when triggers.is_instead_of_trigger = 0 then 'AFTER' 5 else null 6 end as [触发器类型描述] 7 from sys.triggers triggers 8 inner join sys.tables tables on triggers.parent_id = tables.object_id 9 where triggers.type ='TR'10 order by triggers.create_date

  4. 查询所有索引

1 select indexs.Tab_Name as [表名],indexs.Index_Name as [索引名] ,indexs.[Co_Names] as [索引列], 2 Ind_Attribute.is_primary_key as [是否主键],Ind_Attribute.is_unique AS [是否唯一键], 3 Ind_Attribute.is_disabled AS [是否禁用] 4 from ( 5 select Tab_Name,Index_Name, [Co_Names]=stuff((select ','+[Co_Name] from 6 ( select tab.Name as Tab_Name,ind.Name as Index_Name,Col.Name as Co_Name from sys.indexes ind 7 inner join sys.tables tab on ind.Object_id = tab.object_id and ind.type in (1,2) 8 inner join sys.index_columns index_columns on tab.object_id = index_columns.object_id and ind.index_id = index_columns.index_id 9 inner join sys.columns Col on tab.object_id = Col.object_id and index_columns.column_id = Col.column_id10 ) t where Tab_Name=tb.Tab_Name and Index_Name=tb.Index_Name for xml path('')), 1, 1, '')11 from (12 select tab.Name as Tab_Name,ind.Name as Index_Name,Col.Name as Co_Name from sys.indexes ind13 inner join sys.tables tab on ind.Object_id = tab.object_id and ind.type in (1,2)14 inner join sys.index_columns index_columns on tab.object_id = index_columns.object_id and ind.index_id = index_columns.index_id15 inner join sys.columns Col on tab.object_id = Col.object_id and index_columns.column_id = Col.column_id16 )tb17 where Tab_Name not like 'sys%'18 group by Tab_Name,Index_Name19 ) indexs inner join sys.indexes Ind_Attribute on indexs.Index_Name = Ind_Attribute.name20 order by indexs.Tab_Name

  5. 显示存储过程内容

SELECT TEXT FROM syscomments WHERE id=object_id('SP_NAME')SP_HELPTEXT 'SP_NAME'

 

转载地址:http://hojqa.baihongyu.com/

你可能感兴趣的文章
NutUI 2.1.0 发布,移动端轻量级 Vue 组件库
查看>>
缓存系列文章--热点key问题
查看>>
CSS动画小结
查看>>
初学乍练:一键部署redis集群
查看>>
从一个骗局谈生活中的基础算法
查看>>
JdbcTemplate使用别名绑定变量
查看>>
详解Apache Kylin安装和踩坑
查看>>
MVC架构中,用户的请求简单梳理
查看>>
RPA机器人为何会在财务共享领域刮起旋风?
查看>>
NGINX的奇淫技巧 —— 2. IF AND 和 OR
查看>>
排列组合技术
查看>>
哈工大发明“电子体毛”,让机器人学会“敏感”
查看>>
上传一张照片,让算法告诉你是否患有抑郁症
查看>>
VR厂商唯晶科技获2800万C+轮融资,曾开发过游戏《圣女之歌》
查看>>
Countly 19.02.1 发布,实时移动和 web 分析报告平台
查看>>
Elasticsearch 公司上市,市值近 50 亿美元
查看>>
TCP连接中time_wait在开发中的影响-搜人以鱼不如授之以渔
查看>>
Oracle数据库机出新帮助不同规模企业迈向云端
查看>>
前端通信:ajax设计方案(六)--- 全局配置、请求格式拓展和优化、请求二进制类型、浏览器错误搜集以及npm打包发布...
查看>>
Android捕获监听Home键、最近任务列表键
查看>>