Shared Stored Procedures

Please refer to

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20517698.html#7969124 "Database Context and referencing user tables"

I have a similar situation to the one in the question above.

I want to be able to share stored procedures between similarly structured databases, and the solution presented suits me fine, but....

1) I have created a few sample test stored procedures in Master, and now I want to either delete them, change them or rename them, but since they are marked system, I am not allowed to. How do I do that? (For obvious reasons there is no sp_unmarkSystem!)

2) I am unconfortable with resorting to the Master table to solve this. Is there another solution to this situation that does not use the Master Database?

Dabas
LVL 27
DabasAsked:
Who is Participating?
 
Anthony PerkinsConnect With a Mentor Commented:
For the record, here is the Stored Procedure and all the relevant warnings:


-- FOR INTERNAL USE ONLY ... DO NOT DOCUMENT --
-- This procedure sets a bit in sysobjects.  This bit has no meaning, various
--      groups (starfigther, davinci, replication) use it for different things
-- MSQL makes no warranty, express or implied, on what objects will or will
--      not have this bit set.  Use at your own risk.
--  
create procedure sp_MS_marksystemobject
    @objname    nvarchar(517)  -- 517 is max for two part name
as
    -- pre-stuff --
    set nocount on

    -- CHECK THE OBJECT NAME --
    if object_id(@objname, 'local') is null
    begin
        raiserror('sp_MS_marksystemobject: Invalid object name ''%ls''',0,1,@objname)
        return 1
    end

    -- CHECK THE OBJECT OWNER (MUST BE A SYSTEM USER) --
    if user_name(ObjectProperty(object_id(@objname, 'local'), 'ownerid'))
                not in ('dbo','INFORMATION_SCHEMA')
    begin
        raiserror('sp_MS_marksystemobject: Object must be owned by a system user.',0,1)
        return 1
    end

    -- DO THE UPDATE --
    begin tran
    dbcc LockObjectSchema(@objname)
    update sysobjects set status = status | 0xC0000000
                        where id = object_id(@objname, 'local')
    commit tran
    return @@error  -- sp_MS_marksystemobject
0
 
Anthony PerkinsCommented:
And here is a very good explanation on the subject:
http://www.windowsitpro.com/Article/ArticleID/22920/22920.html
0
 
DabasAuthor Commented:
Thanks Anthony.
I also had a look at that stored procedure.
In short, after reading through it,  I prefered to seek advice here rather than stick my fingers into the Master Database....

Dabas
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Anthony PerkinsCommented:
>>I prefered to seek advice here rather than stick my fingers into the Master Database....<<
I don't blame you.  I would not do what you are doing in the first place, but that is just me  ...

Here is Scott's solution to your problem:
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20529165.html

Notice how he is just fliping the bits back.

I would wait for his comment to award him the points.

P.S. Make sure you have a good backup of the Master database.
0
 
DabasAuthor Commented:
G'day Anthony:

Thanks for the link, and yes it works! (See my note at the end of that question)
I will wait for Scott before allocating points, but would also like to hear of alternatives that do not force my fingers to tremble when I type USE MASTER

Dabas
0
 
Anthony PerkinsCommented:
You are a braver man than I.
0
 
DabasAuthor Commented:
acperkins:
> I would wait for his comment to award him the points.
Well, Scott never showed up, and there was nobody else to award the points to.....

Dabas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.