SQL Server查询数据库所有存储过程、触发器、索引信息SQL分享
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分享的更多相关文章
- [转] sql server 跨数据库调用存储过程
A库存储过程: create PROCEDURE [dbo].[spAAAForTest] ( ) =null , ) =null ) AS BEGIN select N'A' AS a , N'B' ...
- SQL Server查询中特殊字符的处理方法 (SQL Server特殊符号的转义处理)
SQL Server查询中特殊字符的处理方法 (SQL Server特殊符号的转义处理) SQL Server查询中,经常会遇到一些特殊字符,比如单引号'等,这些字符的处理方法,是SQL Server ...
- SQL SERVER查询数据库所有的表名/字段
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='subject' --表名 1.利用sysobjects系统表 在这个表中,在数据 ...
- sql server 查询数据库所有的表名+字段
SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='Account' SELECT (case when a.colorder= ...
- sql server 跨数据库调用存储过程
A库存储过程: create PROCEDURE [dbo].[spAAAForTest] ( ) =null , ) =null ) AS BEGIN select N'A' AS a , N'B' ...
- Oracle和SQL server查询数据库中表的创建和最后修改时间
有时候我们需要查看下数据数据库中表的创建时间和最后修改时间,可以通过以下语句实现: Oracle数据库 -- 查看当前用户下的表 SELECT * FROM USER_TABLES -- 查看数据库中 ...
- sql server查询数据库连接数
设置最大连接数 下面的T-SQL 语句可以配置SQL Server 允许的并发用户连接的最大数目. exec sp_configure 'show advanced options', 1exec s ...
- SQL Server —— 查询数据库、表、列等
一.查询数据库(sys.databases —— select *from sys.databases where name='<数据库名>') select *from sys.data ...
- Sql server 查询数据库中包含某字段的所有的表
我们有时候会需要查询数据库中包含某字段的所有的表,去进行update,这时就可以用下面的SQL来实现: select object_name(id) objName,Name as colName f ...
随机推荐
- Day032--Python--操作系统, process进程
多道技术背景: 提高工作效率(充分利用I/O阻塞的时间) (I: input, O: output) 同时执行多个任务 多道技术: 空间复用: 充分利用内存空间 时间复用: 充分利用I/O阻塞时 ...
- Luogu P3181 [HAOI2016]找相同字符 广义$SAM$
题目链接 \(Click\) \(Here\) 设一个串\(s\)在\(A\)中出现\(cnt[s][1]\)次,在\(B\)中出现\(cnt[s][2]\)次,我们要求的就是: \[\sum cnt ...
- (链表 双指针) leetcode 19. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head. Example: Given l ...
- python异步编程之asyncio(百万并发)
前言:python由于GIL(全局锁)的存在,不能发挥多核的优势,其性能一直饱受诟病.然而在IO密集型的网络编程里,异步处理比同步处理能提升成百上千倍的效率,弥补了python性能方面的短板,如最 ...
- makefile解析:一些常用函数
#======================================================================= #指定目标文件名,makefile中的变量直接使用不用 ...
- BZOJ4698 差分 + 二分 + SA
https://www.lydsy.com/JudgeOnline/problem.php?id=4698 题意:求N个字符串中最长的相同字串的长度,相同的定义是:两个子串长度相同且一个串的全部元素加 ...
- java代码的编译执行过程
- Oracle基础--创建临时表空间/表空间/创建用户/授权
总结:创建用户一般分四步: 第一步:创建临时表空间(创建用户之前要创建"临时表空间",若不创建则默认的临时表空间为temp.) SQL> CREATE TEMPORARY T ...
- MySQL中的主键,外键有什么作用详解
MySQL中的主键,外键有什么作用详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 学关系型数据库的同学,尤其在学习主键和外键时会产生一定的困惑.那么今天我们就把这个困惑连根拔起 ...
- js静态方法与实例方法定义,js回调方法定义
主要为了回调方法,随便把静态言法和实例方法也回顾一下. <script type="text/javascript"> var fun = { //下面是静态方法(第一 ...