Home All Groups Group Topic Archive Search About

How to add sproc to multiple databases

Author
20 Jan 2006 6:23 PM
bill
Hi all. Lets say I had a script to run (create sproc) and I needed to
run it on several different databases on one sql server. Can someone
give me an idea how I could do that short of changing the "use databse"
line each time?
Thanks

Author
20 Jan 2006 6:37 PM
ML
See if this helps:
http://www.mssqlcity.com/FAQ/Devel/sp_msforeachdb.htm

But be warned that this is an undocumented and unsupported system procedure.


ML

---
http://milambda.blogspot.com/
Author
20 Jan 2006 6:54 PM
InfoSponge3000
You can also consider instead of having multiple copies of the proc,
just put one copy in the master database... make sure it is prefixed
with "sp_" so it can be executed from any database on that server.

I haven't tried this out myself.  Be careful of any name collisions
from future service packs or upgrades.
Author
20 Jan 2006 11:27 PM
Louis Davidson
Personally, while I have done this in the past, I am starting to shy away
from this practice.  It does work, but the problem here is the same problem
as DLL hell.  So I have a utility procedure named sp_stringParse, or
whatever.  I use this in three databases, and I really think it needs to be
improved for a task in database 3.  So do I have a sp_stringParse_version1,
sp_stringParse_version2?  Maybe, but instead I just put utility procedures
in the database and upgrade them as required in each system.  It also saves
me in that if I don't use the new version immediately, I don't have to test
the code in the other databases until I upgrade it.

It is essential however that you use some sort of versioning process with
SourceSafe, CVS, or even just naming the files differently so you can apply
the latest versions as you discover a need to upgrade the proc in another
database.

Just my $.03 worth :)

--
----------------------------------------------------------------------------
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)

<InfoSponge3***@gmail.com> wrote in message
Show quote
news:1137783245.156785.87200@g43g2000cwa.googlegroups.com...
> You can also consider instead of having multiple copies of the proc,
> just put one copy in the master database... make sure it is prefixed
> with "sp_" so it can be executed from any database on that server.
>
> I haven't tried this out myself.  Be careful of any name collisions
> from future service packs or upgrades.
>

AddThis Social Bookmark Button