[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Shared Stored Procedures

Posted on 2005-05-05
7
Medium Priority
?
421 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:Dabas
  • 4
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 1000 total points
ID: 13942417
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13942428
And here is a very good explanation on the subject:
http://www.windowsitpro.com/Article/ArticleID/22920/22920.html
0
 
LVL 27

Author Comment

by:Dabas
ID: 13942439
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13942446
>>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
 
LVL 27

Author Comment

by:Dabas
ID: 13942486
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13942529
You are a braver man than I.
0
 
LVL 27

Author Comment

by:Dabas
ID: 14084778
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question