Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Thoughts on ALTER vs. DROP & CREATE.

Author  Topic 

readysetstop
Posting Yak Master

123 Posts

Posted - 2006-11-08 : 11:28:37
Thought I should post in the newbie forum for a while, instead. :-)

I have a couple of scripts that I've generated that drop a couple of system stored procedures and recreate them. I'm not sure why I did it in the first place, but I think it was that it wouldn't let me run an ALTER statement on them. Specifically, I'm now looking at sp_add_operator. I changed it to a 500 character email field instead of whatever it was (100, I think.)

/* Explanation: Why did I do that? SQL Mail is prohibited here, so I'm using CDO_Sysmail to email myself and the developers if a job fails. The list of people to email is determined by the owner of the database, who is also an operator in SQL. I get the list of emails from the email field of the operator properties. Hence, I need a bigger email field. Yes, I now know it would most likely be better to create an ADMIN database on each server for this kind of stuff. (Thanks to Tara for that blogged suggestion.) */

While I will probably go back to the default stored procedure, this got me to thinking: when would it be better to use an ALTER statement on a SProc rather than to do a DROP and CREATE?

Your thoughts, oh SQL gurus?

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-11-08 : 11:31:51
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=73313
Go to Top of Page

readysetstop
Posting Yak Master

123 Posts

Posted - 2006-11-08 : 11:55:15
Good info. Thanks.

-D.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-11-08 : 12:52:19
Don't use ALTER

DROP/Create WITH Permissions


And don't let rob's comments in the link be lost on you..I have seen the cached plan use an old one even with drop/create....gotta be less of a problem than ALTER

MOO




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-08 : 12:58:38
Are you naming your own Sprocs using an sp_ prefix (as per "sp_add_operator")?

If so I'm afraid it aint a good idea, see: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Naming+Store+Procedures

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-11-08 : 13:09:29
Well that's only good if they are adding it to master only...which usually isn't a good idea
in the first place...but I have seen reccomendations on doing that...never had a good reason o do that though




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

readysetstop
Posting Yak Master

123 Posts

Posted - 2006-11-08 : 13:16:52
Brett & Kristen:

Points taken. I'll come up with something else for naming, and start re-evaluating the procs we're using. I'm thinking I need a separate database (or maybe server) for some of this admin stuff.

Kristen, I'm actually changing master.dbo.sp_add_operator. (Yes, I know it's a bad idea. Working on a replacement.) :-)

-D.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-08 : 13:19:21
master.dbo.sp_add_operator is fine - you will be able to use sp_add_operator from any database (assuming that's what you want!)

Just to clarify (doubt its needed, but!):

USE MyDatabase
EXEC sp_add_operator

will use the version of sp_add_operator in MASTER, regardless of whether a version also exists in MyDatabase.
Go to Top of Page

readysetstop
Posting Yak Master

123 Posts

Posted - 2006-11-08 : 13:41:42
OK, so maybe not so bad to alter master.dbo.sp_add_operator, then, as long as that is the one you're intending to use. Gotcha. It would be the only one I use anyway.

I do have a couple user defined functions that I have added to the master db. I wanted them to be available for use from every DB. Stuff like input file status checks, and the cdo_sysmail SProcs. I'm assuming this is OK...?

-D.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-11-08 : 13:45:14
Wait, hold the phone.

Is that a sproc you wrote or a system sproc. If it's a system sproc, then it's a very bad idea to change it...can you even change system procs?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

readysetstop
Posting Yak Master

123 Posts

Posted - 2006-11-08 : 14:38:30
Apparently you can. :-)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-08 : 17:10:23
You can roll your own, of course, based on a pre-existing system one:

USE master
sp_helptext 'sp_add_operator'

modify as appropriate, change the name to [sp_MY_add_operator], and Bobs-your-Uncle!

I didn't twig that this was a system Sproc first-up, sorry about that - I could have been a bit quicker out of the block. Well caught Brett ... but time to get back to Blogging "Early days but long nights with 2K5"

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-11-08 : 19:38:09
well caught?

I sure I'm still well behind



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -