Getting the result columns of table valued functions in SQL Server 2008 R2

倾然丶 夕夏残阳落幕 提交于 2019-12-21 04:12:30

问题


For a constants generator I like to get the meta data of result columns for all my table valued functions (what are the names of the columns returned by each table valued function). How can I get them? Do I have to parse the function's source code or is there an interface providing this information?

Thanks for your help

Chris

The following query I use to get the TVFs:

SELECT udf.name AS Name, SCHEMA_NAME(udf.schema_id) AS [Schema]
FROM master.sys.databases AS dtb, sys.all_objects AS udf
WHERE dtb.name = DB_NAME() 
AND (udf.type IN ('TF', 'FT')) 
AND SCHEMA_NAME(udf.schema_id) <> 'sys'

回答1:


This information is available in sys.columns

Returns a row for each column of an object that has columns, such as views or tables. The following is a list of object types that have columns:

  • Table-valued assembly functions (FT)

  • Inline table-valued SQL functions (IF)

  • Internal tables (IT)

  • System tables (S)

  • Table-valued SQL functions (TF)

  • User tables (U)

  • Views (V)

SELECT *
FROM sys.columns
WHERE object_id=object_id('dbo.YourTVF')


来源:https://stackoverflow.com/questions/12052276/getting-the-result-columns-of-table-valued-functions-in-sql-server-2008-r2

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