How to retrieve metadata for return values of an sql server stored procedure

风格不统一 提交于 2019-12-23 02:42:40

问题


I want to analyze an SQL Server stored procedure from .NET code to retrieve metadata for the data/columns it returns (not OUTPUT parameters). Like when you drag/drop a sp on a DataSet i VisualStudio and it automatically generates columns. It could be useful for me for some code generation I'm testing out.

The procedures contains simple select statements like SELECT a,b FROM c and I'd like to get metadata about a and b.


回答1:


You can use SET FMTONLY ON (and execute it) - but this is a bit hit-n-miss. It doesn't cover all scenarios (branches, etc) - and can still execute some code (extended stored procedures etc).

Alternatively - use table-valued-functions (udfs) - they have much richer/more-formal metadata.




回答2:


In SQL Server 2012 /Denali you can use sys.dm_exec_describe_first_result_set_for_object.

This returns information about the first result set in the procedure (as long as this result set is returned by all code paths)



来源:https://stackoverflow.com/questions/516552/how-to-retrieve-metadata-for-return-values-of-an-sql-server-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!