One of the best practicies i follow is not adding objects in master, but lately I have been thinking about actually adding some system stored procedures. I have a handful of procedures that I use to optimize / analyze the server and I use them in a user defined database, but to be able to get information about objects (like index names) from a specific database I need to pass a parameter for the DBname and use dynamic SQL to get the expected results.
If I add the procedures in master and use the sp_ prefix, then it would be possible to use the procedure from any database without passing the database name. It would even be possible to get all information from all the databases at once. (as long as I use the undocumented procedure to mark the procedure as a system stored procedure.)
USE MASTER
GO
EXEC sp_ms_marksystemobject
I know the implications of adding objects in master:
- The procedure may get incompatible in upgrades (but that is the case where ever i put the procedure)
- I may need to add the procedure everytime the SQL server i patched or when master is rebuilt, but that's not a critical problem.
- Security risks, but that can be handled in a couple of different way, (like EXECUTE AS) and the procedures are only used for "system maintenance" and optimizations.
- Need to backup master database more frequent, but the procedures only returns a resultset and not updating any data (unless I add the script for defragmentation of indexes that keeps statistics of how often the indexes get fragmented, but that is not crucial data).
- etc
Is it so evil to add them as system stored procedures? Would you or are you using the master database for "user defined system stored procedures"?
↧