February 15, 2012 at 1:25 am
is it possible to create a function which is available for all Databases(i.e)
when i create a procedure with the prefix of SP_ in the master Database it is visible to all other Database but is it possible to create such Function in mssql server, or is any other way to do it
Every rule in a world of bits and bytes, can be bend or eventually be broken
MyBlog About Common dialog control
A Visualizer for viewing SqlCommand object script [/url]
February 15, 2012 at 2:50 am
Yes - nothing special is required - on an instance of SQL Server, you can access functions in a database from any other database (subject to access rights), using suitably qualified object names (database.schema.fn_fname()).
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
February 16, 2012 at 2:59 am
Phil Parkin (2/15/2012)
Yes - nothing special is required - on an instance of SQL Server, you can access functions in a database from any other database (subject to access rights), using suitably qualified object names (database.schema.fn_fname()).
Phil is 100% right. Just for design consideration, I would advise creating separate database (for example you can call it GlobalUtils) and put all of you "public" procs and functions into it and grant to public to execute them all.
BTW, it's not very good idea to add procs with sp_ prefix into master database.
February 16, 2012 at 7:25 am
I agree with Eugene. Probably not a good idea to put all of these types of things in master. I also agree that a separate database is good for these types of things but I don't agree that you should use fully qualified names in your code. Stick to the 2 part naming convention and use synonyms to point to the functions. That way, if you ever buy 3rd party software that just happens to use your "function repository" database, you don't have a whole bunch of code to change... just a handful of synonyms.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply