是否可以选择存储过程将接收的变量?
例如,我有一个客户表,我的主键是一个自动数字长的数字。
我的存储过程称为SelectClientByKey
,类似于
select *
from clients
where clientId = @clientid
我还有许多其他存储过程,我想进行查询以获取该存储过程具有的变量及其数据类型。
类似的东西:
Select Variable, Type
From StoredProcedure
Where StoredProcedure.Name = 'SelectClientByKey'
结果应为
@clientId bigInt
我不确定是否可行,有什么建议吗?
答案 0 :(得分:2)
从here被无耻地偷走了。如果运行它,它将为您提供所有存储过程及其参数的列表以及一些有用的扩展信息。
SELECT
SCHEMA_NAME(SCHEMA_ID) AS [Schema],
SO.name AS [ObjectName],
SO.Type_Desc AS [ObjectType (UDF/SP)],
P.parameter_id AS [ParameterID],
P.name AS [ParameterName],
TYPE_NAME(P.user_type_id) AS [ParameterDataType],
P.max_length AS [ParameterMaxBytes],
P.is_output AS [IsOutPutParameter]
FROM sys.objects AS SO
INNER JOIN sys.parameters AS P
ON SO.OBJECT_ID = P.OBJECT_ID
WHERE SO.OBJECT_ID IN (
SELECT OBJECT_ID
FROM sys.objects
WHERE TYPE IN ('P','FN')
)
ORDER BY [Schema], SO.name, P.parameter_id
GO
答案 1 :(得分:0)
有可能。您可以使用下面的SQL查询来获取存储过程,参数列表及其数据类型:
SELECT
o.name as StoredProcedure, p.name as Parameter, t.name as DataType
FROM
sys.all_objects o
JOIN
sys.parameters p ON p.object_id = o.object_id
JOIN
sys.types t ON t.system_type_id = p.system_type_id
WHERE
o.name = 'SelectClientByKey' -- Your stored procedure name