How to get stored procedure parameters details?

前端 未结 11 1199
名媛妹妹
名媛妹妹 2020-12-08 01:58

Where can I find information about stored procedure parameters? In my situation I need to know only the input parameters of given store procedure.

In the sys.o

相关标签:
11条回答
  • 2020-12-08 02:51

    Information Schemas are are ISO standard SQL. The PARAMETERS information schema view displays a list of parameters for user-defined functions and stored procedures in the current or specified database. This is one I use to get a list of all parameters for all procedures:

    SELECT          SPECIFIC_NAME,  PARAMETER_MODE, PARAMETER_NAME, DATA_TYPE 
    FROM            INFORMATION_SCHEMA.PARAMETERS
    ORDER BY        SPECIFIC_NAME
    
    0 讨论(0)
  • 2020-12-08 02:51

    Probably a little late , but since the search term Get parameters for all stored procedure on SQL on google, landed me this page, I will post that solution (which is also bit different from other answers in terms of join)

     Select PROCS.name As StoredProcName,TYPE_NAME(user_type_id) As ParameterType,PARAMS.name As Params from sys.procedures PROCS
    JOIN sys.parameters PARAMS WITH(NOLOCK) ON PROCS.object_id = PARAMS.object_id
    Order by PROCS.object_id
    
    0 讨论(0)
  • 2020-12-08 02:52

    An extension of Raj's answer above

    ;WITH CTE
     AS (SELECT OBJECT_NAME(OBJECT_ID) AS  sql_module_name
               ,CASE
                    WHEN OBJECTPROPERTY(OBJECT_ID,'IsProcedure') = 1 THEN 'Stored Procedure'
                    WHEN OBJECTPROPERTY(OBJECT_ID,'IsScalarFunction') = 1 THEN 'Scalar Function'
                    WHEN OBJECTPROPERTY(OBJECT_ID,'IsTableFunction') = 1 THEN 'Table Function'
                END AS                     sql_module_type
               ,parameter_id AS            parameter_order
               ,name AS                    parameter_name
               ,is_nullable AS             parameter_is_nullable_flag
               ,is_output AS               parameter_is_output_flag
               ,TYPE_NAME(user_type_id) AS parameter_type
               ,max_length AS              parameter_length
               ,CASE
                    WHEN TYPE_NAME(system_type_id) = 'uniqueidentifier' THEN precision
                    ELSE OdbcPrec
                         (system_type_id,max_length,precision
                         )
                END AS                     parameter_precision
               ,OdbcScale
                (system_type_id,scale
                ) AS                       parameter_scale
         FROM   sys.parameters)
     SELECT DENSE_RANK() OVER(
            ORDER BY sql_module_type
                    ,sql_module_name ASC) AS group_id
           ,sql_module_name
           ,sql_module_type
           ,parameter_order
           ,parameter_name
           ,parameter_is_nullable_flag
           ,parameter_is_output_flag
           ,parameter_type
           ,parameter_length
           ,parameter_precision
           ,parameter_scale
     FROM   CTE
     ORDER BY sql_module_type
             ,sql_module_name
             ,parameter_order;
    
    0 讨论(0)
  • 2020-12-08 02:56

    For a supplied procedure name, the following query lists all of its parameters and their order along with their type and the type's length (for use with VARCHAR, etc.)

    Replace procedure_name with the name of your procedure.

    DECLARE @ProcedureName VARCHAR(MAX) = 'procedure_name'
    
    SELECT
        pa.parameter_id AS [order]
        , pa.name AS [name]
        , UPPER(t.name) AS [type]
        , t.max_length AS [length] 
    FROM sys.parameters AS pa 
    INNER JOIN sys.procedures AS p on pa.object_id = p.object_id 
    INNER JOIN sys.types AS t on pa.system_type_id = t.system_type_id AND pa.user_type_id = t.user_type_id
    WHERE p.name = @ProcedureName
    
    0 讨论(0)
  • 2020-12-08 03:05
    select * from sys.parameters 
    inner join sys.procedures on parameters.object_id = procedures.object_id 
    inner join sys.types on parameters.system_type_id = types.system_type_id AND parameters.user_type_id = types.user_type_id
    where procedures.name = 'sp_name'
    
    0 讨论(0)
提交回复
热议问题