开发者

Can I add a User Defined Function at the server level in SQL Server 2008 r2?

开发者 https://www.devze.com 2023-02-07 05:31 出处:网络
I need to create a function that can be used across all databases in my SQL Instance. Can I add a User Defined Function at the server level开发者_运维百科 in SQL Server 2008 r2?I would create a small

I need to create a function that can be used across all databases in my SQL Instance. Can I add a User Defined Function at the server level开发者_运维百科 in SQL Server 2008 r2?


I would create a small database for yourself called "Tools" or something like that to store these kinds of functions. Then reference them with a fully qualified name where you need them: Tools.dbo.MyUDF.

Avoid the temptation to store things like this in the Master database. That database belongs to SQL Server and should not be used for such purposes.


Only by adding it to the master database. You might want to give it the sp_ prefix so that it is looked for in the master database automatically. Additionally dependent upon the purpose of the function you might need to mark it as a system object.


No, a UDF must be created in a particular DB.

A UDF in any DB can be used in any other DB as long as the SQL Server login for the relevant executing user(s) have sufficient permission to do so. One reason to create such UDFs in a separate, meaningfully-named DB would be to clearly document the purpose of the UDF (and any other objects you might create in that DB) for other users, administrators, support techs, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号