SQL Server - “sys.functions”在哪里?
SQL Server 2005 在我经常使用的系统目录上有很棒的 sys.XXX
视图。
让我困惑的是:为什么有一个 sys.procedures 视图来查看有关存储过程的信息,但没有 sys.functions 视图来查看您的存储过程的信息存储函数?
没有人使用存储函数吗? 我发现它们对于例如计算列等非常方便!
缺少 sys.functions
是否有特定原因,或者只是认为它不够重要而无法放入 sys
目录视图中? 它在 SQL Server 2008 中可用吗?
SQL Server 2005 has great sys.XXX
views on the system catalog which I use frequently.
What stumbles me is this: why is there a sys.procedures
view to see info about your stored procedures, but there is no sys.functions
view to see the same for your stored functions?
Doesn't anybody use stored functions? I find them very handy for e.g. computed columns and such!
Is there a specific reason sys.functions
is missing, or is it just something that wasn't considered important enough to put into the sys
catalog views? Is it available in SQL Server 2008?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我发现 UDF 非常方便,我一直在使用它们。
我不确定 Microsoft 在 SQL Server 2005(或 SQL Server 2008,据我所知)中不包含 sys.functions 等效项的理由是什么,但很容易推出您自己的:
I find UDFs are very handy and I use them all the time.
I'm not sure what Microsoft's rationale is for not including a sys.functions equivalent in SQL Server 2005 (or SQL Server 2008, as far as I can tell), but it's easy enough to roll your own:
列出函数的另一种方法是使用 INFORMATION_SCHEMA 视图。
根据 Microsoft 网站,“信息架构视图提供了 SQL Server 元数据的内部、独立于系统表的视图。尽管对底层系统表进行了重大更改,但信息架构视图使应用程序能够正常工作”。 换句话说,随着 SQL 升级,底层系统表可能会发生变化,但视图仍应保持不变。
Another way to list functions is to make use of INFORMATION_SCHEMA views.
According to the Microsoft web site "Information schema views provide an internal, system table-independent view of the SQL Server metadata. Information schema views enable applications to work correctly although significant changes have been made to the underlying system tables". In other words, the underlying System tables may change as SQL gets upgraded, but the views should still remain the same.
根据 SSMS 在编写函数的 DROP 脚本时生成的内容,这在 2008 R2 中有效:
This is valid in 2008 R2 per what SSMS generates when you script a DROP of a function:
它稍微冗长一些,但这应该做完全相同的事情:
据我所知,它也不在 SQL Server 2008 中。
It's very slightly more verbose, but this should do exactly the same thing:
As far as I can see, it's not in SQL Server 2008 either.
这并没有添加任何新内容,但我发现以下内容更容易记住:
This does not add anything new, but I found the following easier to remember:
要扩展@LukeH的答案,要返回函数定义也需要连接到
sys.sql_modules
表。 所以对此的查询是:上面分别显示函数名称、其定义和对象标识符。
To extend upon @LukeH's answer, to return the function definitions as well requires a join to the
sys.sql_modules
table. So the query for this is:where the above displays the function name, its definition and the object identifier respectively.
尝试这个 :
try this :
有关标量函数(包括所有者和返回类型)的更完整描述:
For a fuller description of scalar functions including owner and return type:
顺便说一句,您不想包含 type = 'FS' 吗?
这就是 sys.objects 中的项目对应于我的 UDF,它是从外部 DLL 派生的
incidentally, wouldn't you want to include type = 'FS'?
that's what the item in sys.objects corresponds with for my UDF which is derived from an external DLL
SQL 2000
特定,对象名称略有调整:OR
SQL 2000
specific, slight adjustment for the object name:OR