什么是包含有关存储过程参数的信息的SQL Server系统表?

时间:2012-05-04 14:49:39

标签: sql-server stored-procedures

什么是SQL Server系统表,其中包含有关存储过程参数的信息,其中包含数据类型,名称,长度,空等信息?

感谢

6 个答案:

答案 0 :(得分:18)

您可以查询sys.procedures和sys.parameters ...

select pr.name, p.*
from sys.procedures pr 
inner join sys.parameters p on pr.object_id = p.object_id

并加入类型......

select pr.name, p.*, t.name, t.max_length
from sys.procedures pr 
inner join sys.parameters p on pr.object_id = p.object_id
inner join sys.types t on p.system_type_id = t.system_type_id

答案 1 :(得分:3)

您也可以使用

select * from INFORMATION_SCHEMA.PARAMETERS

答案 2 :(得分:1)

您也可以使用

select * from INFORMATION_SCHEMA.ROUTINES \G;

答案 3 :(得分:0)

SELECT 
    p.name AS [SP Name], qs.execution_count,
    ISNULL(qs.execution_count/DATEDIFF(Second, qs.cached_time, GETDATE()), 0) AS [Calls/Second],
    qs.total_worker_time/qs.execution_count AS [AvgWorkerTime], qs.total_worker_time AS [TotalWorkerTime],  
    qs.total_elapsed_time, qs.total_elapsed_time/qs.execution_count AS [avg_elapsed_time],
    qs.cached_time,
    isr.ROUTINE_DEFINITION
FROM sys.procedures AS p
INNER JOIN sys.dm_exec_procedure_stats AS qs
ON p.[object_id] = qs.[object_id]
Inner Join INFORMATION_SCHEMA.ROUTINES as ISR
on p.name = isr.SPECIFIC_NAME
WHERE qs.database_id = DB_ID()
    and
    isr.ROUTINE_DEFINITION like '%XXXX%'  -- name of something you are looking for in the stored procedure

ORDER BY qs.execution_count DESC OPTION (RECOMPILE);

答案 4 :(得分:0)

对于那些使用SQL 2000的人

SELECT * FROM [dbName]..sysobjects  WHERE xtype = 'P'

SELECT * FROM [dbName]..sysComments

按ID

加入他们

答案 5 :(得分:0)

这显示有关存储过程和用户​​定义函数的信息。它将包括不带参数的过程/标量函数,但将包括参数信息(如果可用)。

SELECT 
O.Name ProcedureName, 
P.parameter_id Position,
P.Name ParameterName, 
P.max_length MaxLen, 
P.is_output IsOutput, 
P.has_default_value HasDefaultValue, 
P.default_value DefaultValue, 
P.is_nullable IsNullable, 
T.name TypeName, 
T.max_length TypeMaxLen,
O.type_desc TypeDescription
FROM SYS.OBJECTS O
LEFT JOIN SYS.PARAMETERS P ON O.object_id = P.object_id
LEFT JOIN SYS.TYPES T ON P.system_type_id = T.system_type_id
WHERE type_desc LIKE 'SQL_%'
ORDER BY O.Name, P.parameter_id, P.Name