SQL Server查询所有存储过程信息、触发器、索引
程序员文章站
2023-12-30 23:13:46
...
SQL Server查询所有存储过程信息、触发器、索引 无 select Pr_Name as [存储过程], [参数]=stuff((select ','+[Parameter]from (select Pr.Name as Pr_Name,parameter.name +' ' +Type.Name + ' ('+convert(varchar(32),parameter.max_length)+')' as Param
SQL Server查询所有存储过程信息、触发器、索引
select Pr_Name as [存储过程], [参数]=stuff((select ','+[Parameter] from ( select Pr.Name as Pr_Name,parameter.name +' ' +Type.Name + ' ('+convert(varchar(32),parameter.max_length)+')' as Parameter from sys.procedures Pr left join sys.parameters parameter on Pr.object_id = parameter.object_id inner join sys.types Type on parameter.system_type_id = Type.system_type_id where type = 'P' ) t where Pr_Name=tb.Pr_Name for xml path('')), 1, 1, '') from ( select Pr.Name as Pr_Name,parameter.name +' ' +Type.Name + ' ('+convert(varchar(32),parameter.max_length)+')' as Parameter from sys.procedures Pr left join sys.parameters parameter on Pr.object_id = parameter.object_id inner join sys.types Type on parameter.system_type_id = Type.system_type_id where type = 'P' )tb where Pr_Name not like 'sp_%' --and Pr_Name not like 'dt%' group by Pr_Name order by Pr_Name
select triggers.name as [触发器],tables.name as [表名],triggers.is_disabled as [是否禁用], triggers.is_instead_of_trigger AS [触发器类型], case when triggers.is_instead_of_trigger = 1 then 'INSTEAD OF' when triggers.is_instead_of_trigger = 0 then 'AFTER' else null end as [触发器类型描述] from sys.triggers triggers inner join sys.tables tables on triggers.parent_id = tables.object_id where triggers.type ='TR' order by triggers.create_date
select indexs.Tab_Name as [表名],indexs.Index_Name as [索引名] ,indexs.[Co_Names] as [索引列], Ind_Attribute.is_primary_key as [是否主键],Ind_Attribute.is_unique AS [是否唯一键], Ind_Attribute.is_disabled AS [是否禁用] from ( select Tab_Name,Index_Name, [Co_Names]=stuff((select ','+[Co_Name] from ( select tab.Name as Tab_Name,ind.Name as Index_Name,Col.Name as Co_Name from sys.indexes ind inner join sys.tables tab on ind.Object_id = tab.object_id and ind.type in (1,2) inner join sys.index_columns index_columns on tab.object_id = index_columns.object_id and ind.index_id = index_columns.index_id inner join sys.columns Col on tab.object_id = Col.object_id and index_columns.column_id = Col.column_id ) t where Tab_Name=tb.Tab_Name and Index_Name=tb.Index_Name for xml path('')), 1, 1, '') from ( select tab.Name as Tab_Name,ind.Name as Index_Name,Col.Name as Co_Name from sys.indexes ind inner join sys.tables tab on ind.Object_id = tab.object_id and ind.type in (1,2) inner join sys.index_columns index_columns on tab.object_id = index_columns.object_id and ind.index_id = index_columns.index_id inner join sys.columns Col on tab.object_id = Col.object_id and index_columns.column_id = Col.column_id )tb where Tab_Name not like 'sys%' group by Tab_Name,Index_Name ) indexs inner join sys.indexes Ind_Attribute on indexs.Index_Name = Ind_Attribute.name order by indexs.Tab_Name
DECLARE @s VARCHAR(4000),@n INT,@i INT,@s1 VARCHAR(100) SELECT IDENTITY(INT) id,text INTO ## FROM syscomments SELECT @n=@@ROWCOUNT,@i=0 WHILE @i0 and charindex('CREATE PROCEDURE',text)>0
SELECT TEXT FROM syscomments WHERE id=object_id('SP_NAME') SP_HELPTEXT 'SP_NAME'
USE [your_database_name_here]; GO SELECT * FROM sys.all_objects WHERE ([type] = 'P' OR [type] = 'X' OR [type] = 'PC') AND [is_ms_shipped] = 0 ORDER BY [name]; GO SELECT * FROM sysobjects where type='P'
推荐阅读
-
SQL Server查询所有存储过程信息、触发器、索引
-
SQL Server 分页查询存储过程代码
-
在SQL Server中使用SQL语句查询一个存储过程被其它所有的存储过程引用的存储过程名
-
SQL SERVER 利用存储过程查看角色和用户信息的写法
-
SQL Server 分页查询存储过程代码
-
在SQL Server中使用SQL语句查询一个存储过程被其它所有的存储过程引用的存储过程名
-
SQL Server 分页查询通用存储过程(只做分页查询用)
-
SQL SERVER 利用存储过程查看角色和用户信息的写法
-
sql server 查询某个表被哪些存储过程调用
-
SQL server 数据库的索引和视图、存储过程和触发器