SQL Server查询所有存储过程信息、触发器、索引
1. [代码]查询所有存储过程
01 |
select Pr_Name as [存储过程], [参数]=stuff(( select ',' +[Parameter] |
02 |
from ( |
03 |
select Pr. Name as Pr_Name,parameter. name + ' ' +Type. Name + ' (' + convert ( varchar (32),parameter.max_length)+ ')' as Parameter |
04 |
from sys.procedures Pr left join |
05 |
sys.parameters parameter on Pr.object_id = parameter.object_id |
06 |
inner join sys.types Type on parameter.system_type_id = Type.system_type_id |
07 |
where type = 'P' |
08 |
) t where Pr_Name=tb.Pr_Name for xml path( '' )), 1, 1, '' ) |
09 |
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. [代码]查询所有触发器
01 |
select triggers. name as [触发器],tables. name as [表名],triggers.is_disabled as [是否禁用], |
02 |
triggers.is_instead_of_trigger AS [触发器类型], |
03 |
case when triggers.is_instead_of_trigger = 1 then 'INSTEAD OF' |
04 |
when triggers.is_instead_of_trigger = 0 then 'AFTER' |
05 |
else null |
06 |
end as [触发器类型描述] |
07 |
from sys.triggers triggers |
08 |
inner join sys.tables tables on triggers.parent_id = tables.object_id |
09 |
where triggers.type = 'TR' |
10 |
order by triggers.create_date |
3. [代码]查询所有索引
01 |
select indexs.Tab_Name as [表名],indexs.Index_Name as [索引名] ,indexs.[Co_Names] as [索引列], |
02 |
Ind_Attribute.is_primary_key as [是否主键],Ind_Attribute.is_unique AS [是否唯一键], |
03 |
Ind_Attribute.is_disabled AS [是否禁用] |
04 |
from ( |
05 |
select Tab_Name,Index_Name, [Co_Names]=stuff(( select ',' +[Co_Name] from |
06 |
( select tab. Name as Tab_Name,ind. Name as Index_Name,Col. Name as Co_Name from sys.indexes ind |
07 |
inner join sys.tables tab on ind.Object_id = tab.object_id and ind.type in (1,2) |
08 |
inner join sys.index_columns index_columns on tab.object_id = index_columns.object_id and ind.index_id = index_columns.index_id |
09 |
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 |
4. [代码][SQL]代码
01 |
DECLARE @s VARCHAR (4000),@n INT ,@i INT ,@s1 VARCHAR (100) |
02 |
SELECT IDENTITY( INT ) id,text INTO ## |
03 |
FROM syscomments |
04 |
SELECT @n=@@ROWCOUNT,@i=0 |
05 |
WHILE @i<@n |
06 |
BEGIN |
07 |
SELECT @i=@i+1,@s= '' |
08 |
SELECT @s1= REPLACE ( REPLACE (RTRIM(LTRIM(STUFF(STUFF(text,CHARINDEX( 'AS' ,text),40000, '' ),1, |
09 |
CHARINDEX( 'PROC' ,STUFF(text,CHARINDEX( 'AS' ,text),40000, '' ))+4, '' ))), CHAR (10), '' ), CHAR (13), '' ) |
10 |
FROM ## WHERE ID=RTRIM(@i) |
11 |
--SELECT @s1,ASCII(SUBSTRING(@s1,3,1)) |
12 |
--SELECT LEN(REPLACE(REPLACE(@s1,CHAR(13),''),CHAR(10),'')) |
13 |
SELECT @s= 'SELECT text FROM tempdb.dbo.## WHERE ID=' + RTRIM(@i) |
14 |
EXEC ( 'EXEC master..xp_cmdshell ' 'bcp "' + @s + ' " queryout "e:\ProcTXT\' + @s1 + ' .txt" -S "ROBINHOME\SQLEXPRESS" -c -U "sa" -P "bd5178" '' ') |
15 |
END |
16 |
DROP TABLE ## |
17 |
18 |
--自己写的 如何识别换行??? 还有些非存储过程的对象 |
19 |
SELECT top 10 text FROM syscomments where id in( |
20 |
select object_id from sys.procedures where type = ' P ') |
21 |
22 |
SELECT text FROM syscomments where id in( |
23 |
select object_id from sys.procedures where type = ' P ') |
24 |
and charindex(' ALLSTOCK ',text)>0 |
25 |
and charindex(' CREATE PROCEDURE ',text)>0 |
5. [代码]显示存储过程内容
1 |
SELECT TEXT FROM syscomments WHERE id=object_id( 'SP_NAME' ) |
2 |
3 |
SP_HELPTEXT 'SP_NAME' |
6. [代码]获取只有用户定义的存储过程
1 |
USE [your_database_name_here]; |
2 |
GO |
3 |
SELECT * FROM sys.all_objects |
4 |
WHERE ([type] = 'P' OR [type] = 'X' OR [type] = 'PC' ) AND [is_ms_shipped] = 0 ORDER BY [ name ]; |
5 |
GO |
6 |
SELECT * FROM sysobjects where type= 'P' |
SQL Server查询所有存储过程信息、触发器、索引的更多相关文章
- 遍历SQL SERVER中所有存储过程和触发器
如果需要查找某个存储过程或触发器中是否含有某段文本(比如:你想知道有哪些存储过程操作了某个表) 可以这么写 select name from sysobjects o, syscomments s w ...
- SQL命令查询Oracle存储过程信息(代码内容等)
SELECT * FROM ALL_SOURCE where TYPE='PROCEDURE' AND TEXT LIKE '%0997500%'; --查询ALL_SOURCE中,(脚本代码)内 ...
- SQL Server 查询性能优化 相关文章
来自: SQL Server 查询性能优化——堆表.碎片与索引(一) SQL Server 查询性能优化——堆表.碎片与索引(二) SQL Server 查询性能优化——覆盖索引(一) SQL Ser ...
- 数据库表设计时一对一关系存在的必要性 数据库一对一、一对多、多对多设计 面试逻辑题3.31 sql server 查询某个表被哪些存储过程调用 DataTable根据字段去重 .Net Core Cors中间件解析 分析MySQL中哪些情况下数据库索引会失效
数据库表设计时一对一关系存在的必要性 2017年07月24日 10:01:07 阅读数:694 在表设计过程中,我无意中觉得一对一关系觉得好没道理,直接放到一张表中不就可以了吗?真是说,网上信息什么都 ...
- Sql Server查询性能优化之走出索引的误区
据了解绝大多数开发人员对于索引的理解都是一知半解,局限于大多数日常工作没有机会.也什么没有必要去关心.了解索引,实在哪天某个查询太慢了找到查询条件建个索引就ok,哪天又有个查询慢了,再建立个索引就是, ...
- SQL Server查询性能优化——堆表、碎片与索引(二)
本文是对 SQL Server查询性能优化——堆表.碎片与索引(一)的一些总结. 第一:先对 SQL Server查询性能优化——堆表.碎片与索引(一)中的例一的SET STATISTICS IO之 ...
- VFP获取 SQL Server 的数据表、触发器、存储过程、视图等脚本
本文代码转载自红雨先生 *-----------------------------------------------* SqlServer 相关函数*----------------------- ...
- SQL Server查询性能优化——覆盖索引(一)
覆盖索引又可以称为索引覆盖. 解释一: 就是select的数据列只用从索引中就能够取得,不必从数据表中读取,换句话说查询列要被所使用的索引覆盖. 解释二: 索引是高效找到行的一个方法,当能通过检索索引 ...
- SQL Server查询性能优化——覆盖索引(二)
在SQL Server 查询性能优化——覆盖索引(一)中讲了覆盖索引的一些理论. 本文将具体讲一下使用不同索引对查询性能的影响. 下面通过实例,来查看不同的索引结构,如聚集索引.非聚集索引.组合索引等 ...
随机推荐
- (转)SQL SERVER 日志已满的处理方法
本文转载自:http://www.cnblogs.com/eycbest/archive/2012/01/04/2311567.html 事务日志文件Transaction Log File是用来记录 ...
- 第4课 Hello QT
1. QT的安装 (1)双击:qt-opensource-windows-x86-mingw492-5.6.0.exe (2)安装过程中指定QT Creator安装目录下的mingw文件夹 (3)设置 ...
- Protocol入门
参考:http://haoxiang.org/2011/08/ios-delegate-and-protocol/ 介绍: Protocol在iOS中就是协议,简单的理解就是一组函数的集合,这个集合中 ...
- python推荐书籍
推荐的python电子书 python学习路线图 优先级 入门:python核心编程 提高:python cookbook 其他 (1).数据分析师 需要有深厚的数理统计基础,但是对程序开发能力不做要 ...
- Selenium Webdriver——实现截图功能
截图方法 public static void snapshot(TakesScreenshot drivername, String filename) { // this method will ...
- Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F
问题描述:从新浪微博抓取消息保存到MySQL数据中,对应数据库字段为varchar,字符编码utf-8.部分插入成功,部分插入失败,报错如标题. 在网上查询,有人说是编码问题,建议修改编码格式,比如改 ...
- 新手C#异常的学习2018.08.07
异常是在程序执行期间出现的问题.C# 中的异常是对程序运行时出现的特殊情况的一种响应,比如尝试除以零. class Program { static void Main(string[] args) ...
- mount /dev/sr0 /media/cdrom you must specify the filesystem type
发现“CD/DVD”的Device status中的“Connected”未打勾,将此项打勾后(不需要重启虚拟机),可以正常挂载光驱
- 分区恢复和NTFS文件恢复试验
一.实验室名称:主楼实验室A2-412 二.实验项目名称:分区恢复和NTFS文件恢复试验 三.实验学时:6学时 四.实验原理: 借助fdisk.diskgen软件对磁 ...
- 使screen支持滚动
在Linux中,常用的串口工具有minicom和screen,minicom可能使用得比较多,但是我比较喜欢screen,因为它的输出是彩色的,更舒服.更能突出重点. 使用screen来打开串口也非常 ...