How to get stored procedure parameters details?

前端 未结 11 1198
名媛妹妹
名媛妹妹 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:39
    select  
       'Parameter_name' = name,  
       'Type'   = type_name(user_type_id),  
       'Length'   = max_length,  
       'Prec'   = case when type_name(system_type_id) = 'uniqueidentifier' 
                  then precision  
                  else OdbcPrec(system_type_id, max_length, precision) end,  
       'Scale'   = OdbcScale(system_type_id, scale),  
       'Param_order'  = parameter_id,  
       'Collation'   = convert(sysname, 
                       case when system_type_id in (35, 99, 167, 175, 231, 239)  
                       then ServerProperty('collation') end)  
    
      from sys.parameters where object_id = object_id('MySchema.MyProcedure')
    
    0 讨论(0)
  • 2020-12-08 02:39

    There are the system tables, like sys.objects or sys.sysobjects.

    Or you could also look at INFORMATION_SCHEMA, specifically INFORMATION_SCHEMA.ROUTINES and INFORMATION_SCHEMA.ROUTINE_COLUMNS.

    Because it is in the ANSI-standard INFORMATION_SCHEMA, there are less SQL Server specific quirks. IMHO it is easier to understand for most things.

    0 讨论(0)
  • 2020-12-08 02:40

    It Contains a row for each parameter of an object that accepts parameters. If the object is a scalar function, there is also a single row describing the return value. That row will have a parameter_id value of 0.

    SELECT *  
    FROM sys.parameters  
    WHERE object_id = object_id('SchemaName.ProcedureName')
    

    Reference: https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-parameters-transact-sql?view=sql-server-2017

    0 讨论(0)
  • 2020-12-08 02:40
    SELECT *  
    FROM INFORMATION_SCHEMA.PARAMETERS 
    WHERE SPECIFIC_NAME='proc_name' 
    ORDER BY ORDINAL_POSITION 
    

    (tested with MSSQL 2014)

    0 讨论(0)
  • 2020-12-08 02:40
    select t1.[name] as [SP_name],t2.[name] as [Parameter_name],
    t3.[name] as [Type],t2.[Length],t2.colorder as [Param_order]
    from sysobjects t1
    inner join syscolumns t2 on t1.[id]=t2.[id]
    inner join systypes t3 on t2.xtype=t3.xtype
    where t1.[name]='My_StoredProc_Name'
    order by [Param_order]
    
    0 讨论(0)
  • 2020-12-08 02:42

    The following Query worked for me:

    SELECT * FROM sys.parameters sp1, sys.procedures sp2 WHERE sp1.object_id = sp2.object_id
    

    For more specific result with parameter order:

    SELECT * FROM sys.parameters sp1, sys.procedures sp2, sys.types st WHERE sp1.object_id = sp2.object_id AND sp2.name = 'usp_nameofstoredprocedure' AND sp1.user_type_id = st.user_type_id ORDER BY sp1.parameter_id asc;
    
    0 讨论(0)
提交回复
热议问题