sql 查看Stored Procedure.sql的存储过程列表和视图定义

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 查看Stored Procedure.sql的存储过程列表和视图定义相关的知识,希望对你有一定的参考价值。

-- how to view all procedures (type = 'p')
SELECT * FROM sys.objects
WHERE type = 'P'

-- How to view list of all stored procedures within a database
SELECT * from DatabaseName.information_schema.routines 
WHERE routine_type = 'PROCEDURE'

-- How to view code used to create stored procedure. Syntax is sp_helptext ProcedureName
sp_helptext lsp_my_stored_procedure

-- Alternate way to view code used to create stored procedure. 
SELECT * from DatabaseName.information_schema.routines 
WHERE routine_type = 'PROCEDURE' -- in results, scroll to the right and find the ROUTINE DEFINITION cell, copy that text and paste into a text editor to see code that created the procedure.

-- how to see the last time a stored procedure has been run. Look for Last_Execution_Time in results table.
SELECT  a.execution_count ,
    OBJECT_NAME(objectid) Name,
    query_text = SUBSTRING( 
    b.text, 
    a.statement_start_offset/2, 
    (	CASE WHEN a.statement_end_offset = -1 
    	THEN len(convert(nvarchar(max), b.text)) * 2 
    	ELSE a.statement_end_offset 
    	END - a.statement_start_offset)/2
    ) ,
    b.dbid ,
    dbname = db_name(b.dbid) ,
    b.objectid ,
    a.creation_time,
    a.last_execution_time,
    a.*
FROM    		sys.dm_exec_query_stats a 
CROSS APPLY 	sys.dm_exec_sql_text(a.sql_handle) as b 
WHERE OBJECT_NAME(objectid) = 'YOURPROCEDURENAME'
ORDER BY a.last_execution_time DESC

以上是关于sql 查看Stored Procedure.sql的存储过程列表和视图定义的主要内容,如果未能解决你的问题,请参考以下文章

stored procedure --存储过程

存储过程(Stored Procedure)与游标(Cursor)

Fluent Nhibernate and Stored Procedures

数据库工程开发秘籍之TSQL 存储过程user stored procedure的概念与案例实战

MySQL Stored Procedure To Insert Test Record

Oracle中的存储过程(Stored Procedure)