0

Is there a way or how to make a global UDF like it can be accessed everywhere (as long as it is inside the scope of your server) in SQL Server?

billinkc
  • 59,250
  • 9
  • 102
  • 159
JanLeeYu
  • 981
  • 2
  • 9
  • 24

2 Answers2

0

Assuming the person calling the UDF has appropriate permissions, you should be able to create the function in any database (including the system databases, though I'd steer clear of that). You can call the function by prefacing the function with the database name. i.e.

SELECT * FROM [database].[dbo].[function_name]

Jeffrey Van Laethem
  • 2,601
  • 1
  • 20
  • 30
  • Yeah I see the point though the function is still owned by the db where it was created.I am actually looking for something like we can say that db1, db2, db3 ... owns this function or this function is shared by all of them. Good point though. – JanLeeYu Feb 18 '16 at 03:19
0

Be aware that UDFs, as a general rule, perform poorly in SQL Server as the optimizer has no means of properly costing them.

You can lessen the suck, if the function does not access tables, by creating it as schemabound

On to the question at hand - how do you get a global function? You can't. You can get global stored procedures by putting them in the master database but functions themselves are treated differently (or procs are treated differently -> half-full or half-empty)

I'd probably go the synonym route myself

Community
  • 1
  • 1
billinkc
  • 59,250
  • 9
  • 102
  • 159