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 Parameter
11 from sys.procedures Pr left join
12 sys.parameters parameter on Pr.object_id = parameter.object_id
13 inner join sys.types Type on parameter.system_type_id = Type.system_type_id
14 where type = 'P'
15 )tb
16 where Pr_Name not like 'sp_%' --and Pr_Name not like 'dt%'
17 group by Pr_Name
18 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 join
3 sys.parameters parameter on Pr.object_id = parameter.object_id
4 inner join sys.types T on parameter.system_type_id = T.system_type_id
5 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_id
10 ) 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 ind
13 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_id
15 inner join sys.columns Col on tab.object_id = Col.object_id and index_columns.column_id = Col.column_id
16 )tb
17 where Tab_Name not like 'sys%'
18 group by Tab_Name,Index_Name
19 ) indexs inner join sys.indexes Ind_Attribute on indexs.Index_Name = Ind_Attribute.name
20 order by indexs.Tab_Name

  5. 显示存储过程内容

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

SP_HELPTEXT 'SP_NAME'

SQL Server查询数据库所有存储过程、触发器、索引信息SQL分享的更多相关文章

  1. [转] sql server 跨数据库调用存储过程

    A库存储过程: create PROCEDURE [dbo].[spAAAForTest] ( ) =null , ) =null ) AS BEGIN select N'A' AS a , N'B' ...

  2. SQL Server查询中特殊字符的处理方法 (SQL Server特殊符号的转义处理)

    SQL Server查询中特殊字符的处理方法 (SQL Server特殊符号的转义处理) SQL Server查询中,经常会遇到一些特殊字符,比如单引号'等,这些字符的处理方法,是SQL Server ...

  3. SQL SERVER查询数据库所有的表名/字段

    SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='subject' --表名 1.利用sysobjects系统表 在这个表中,在数据 ...

  4. sql server 查询数据库所有的表名+字段

    SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='Account' SELECT    (case when a.colorder= ...

  5. sql server 跨数据库调用存储过程

    A库存储过程: create PROCEDURE [dbo].[spAAAForTest] ( ) =null , ) =null ) AS BEGIN select N'A' AS a , N'B' ...

  6. Oracle和SQL server查询数据库中表的创建和最后修改时间

    有时候我们需要查看下数据数据库中表的创建时间和最后修改时间,可以通过以下语句实现: Oracle数据库 -- 查看当前用户下的表 SELECT * FROM USER_TABLES -- 查看数据库中 ...

  7. sql server查询数据库连接数

    设置最大连接数 下面的T-SQL 语句可以配置SQL Server 允许的并发用户连接的最大数目. exec sp_configure 'show advanced options', 1exec s ...

  8. SQL Server —— 查询数据库、表、列等

    一.查询数据库(sys.databases —— select *from sys.databases where name='<数据库名>') select *from sys.data ...

  9. Sql server 查询数据库中包含某字段的所有的表

    我们有时候会需要查询数据库中包含某字段的所有的表,去进行update,这时就可以用下面的SQL来实现: select object_name(id) objName,Name as colName f ...

随机推荐

  1. mybatis 直接执行sql 【我】

    Connection conn = getConnection();//            Connection conn = this.ss.getConnection(); 返回Connect ...

  2. 第二十九节,目标检测算法之R-CNN算法详解

    Girshick, Ross, et al. “Rich feature hierarchies for accurate object detection and semantic segmenta ...

  3. 深入理解之css中的border属性

    1. border-width:不支持不百分比 1)受本身的使用场景决定. 例子:左边为手机,右边为显示器,但是他们边框的宽度是差不多的,不会因为设备大就让边框宽度变大. 2. border-widt ...

  4. mac上安装虚拟机

    1.Mac | 怎么安装虚拟机 2.Mac | 怎么安装VMware Fusion虚拟机 资源下载链接: 1.win7旗舰版-64位.iso 2.VMFusion811.rar

  5. 怎么用ajax下载文件

    可能大家都觉得没有必要用ajax来下载东西,用window.open(url)就可以搞定 但是这有一个问题,就是这就限定了只能用GET方式来请求了: 可能你又会说GET很符合REST的要求呀. 但是如 ...

  6. dubbo基础

    一.什么是dubbo,有什么用 dubbo是阿里巴巴开源的一个RPC框架,用于多个应用相互通信.使用dubbo需要安装一zookepper 二.dubbo的基本使用 1.构建一个maven的多模块项目 ...

  7. Java面试题全集(下)转载

    Java面试题全集(下)   这部分主要是开源Java EE框架方面的内容,包括hibernate.MyBatis.spring.Spring MVC等,由于Struts 2已经是明日黄花,在这里就不 ...

  8. HDFS 上文件块的副本数设置

    一.使用 setrep 命令来设置 # 设置 /javafx-src.zip 的文件块只存三份 hadoop fs -setrep /javafx-src.zip 二.文件块在磁盘上的路径 # 设置的 ...

  9. Netsarang

    下载 https://www.netsarang.com/zh/all-downloads/ 建议直接下载 xmanager-power-suite,里面包含了 Xmanager.Xshell.Xft ...

  10. MyBatis-${}与#{}

    一.看两种取值的效果 <select id="selectMyUserIdAndAge" resultType="myUser"> select * ...