Sql获取具有数据类型和精度的列名

时间:2014-12-13 04:02:01

标签: sql-server-2014

大家好我写了一个存储过程,显示参数值和数据类型如下

SELECT SCHEMA_NAME(SCHEMA_ID) AS [Schema], 
P.name AS [Parameter],
TYPE_NAME(P.user_type_id) AS [DataType]
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')) AND SO.name = 'User_Update'
ORDER BY [Schema], SO.name, P.parameter_id

但是我想查询它显示如下,以及它是否是强制性的,有人可以帮助我

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以从此查询开始:

select top 10 SCHEMA_NAME(o.schema_id) AS [Schema], o.name AS [Function]
, p.parameter_id, p.name, t.name, t.max_length, t.precision, t.scale 
from sys.objects as o
    inner join sys.parameters as p on p.object_id = o.object_id
    inner join sys.types as t on t.system_type_id = p.system_type_id
where o.type in ('P','FN') AND o.name = 'User_Update'
    --  and p.name <> '' / p.parameter_id >= 1 remove output parameter
order by o.name, p.parameter_id

您需要的信息在sys.parameters中。

提示:

  • 对于char或varchar,您可以查看max_length。
  • 对于数字,您可以查看精度和比例
  • 参数0是标量函数的输出