Solved

Modifiying an SP

Posted on 2009-05-17
10
224 Views
Last Modified: 2012-05-07
This is embarrassing to type - I am sure I must be missing something obvious.
In sql 2000 when I wanted to modify an sp (and was feeling lazy) I would right click it (EM) , choose properties alter the text and execute it.

I want to alter a SP in 2005 so I right click (SSMS) and choose modify.
First thing I notice is that the actual SP itself is in quotes and is a parameter for dbo.sp_executesql
So (inside the quotes) I make my change. Very simple, all I need to do is add an oder by.
I run it and all seems fine, but the data is not ordered by anything. I revisit the SP (modify) and my changes are gone.
If I re-type the changes and run the alter SP statement by itself then all is fine.

What is the purpose of this right click modify command if it's not going to make/save my changes?
0
Comment
Question by:QPR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24407648
>So (inside the quotes) I make my change
once you made your changes, you have to complile that sp by pressing F5, otherwise the changes made on the sp wont remain there. I hope you missed to do that
0
 
LVL 29

Author Comment

by:QPR
ID: 24407661
I click "execute"
Command(s) completed successfully.

I close the window and am asked if I want to save sqlquery01.sql and I say no.
I reopen the SP and my changes are not there.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24408028
are you reopening the sp through management studio?  can you post the code that you're running to alter your proc?  
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 29

Author Comment

by:QPR
ID: 24408070
yes everything via SSMS
In the example below, I can delete order by id desc.
Then I will execute and it will say all good.
I run the SP (from the web front end) and the order by will still be in effect.
Go back to SSMS and the orderby is still part of the sql


USE [Intranet]
GO
/****** Object:  StoredProcedure [dbo].[GetCDEMannounce]    Script Date: 05/18/2009 10:15:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCDEMannounce]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'ALTER procedure [dbo].[GetCDEMannounce]
as
select FullItem
from dbo.CDEMAnnounce
where StartDate <= getDate()--dateadd(d,-1,getDate())
	and ExpireDate > getDate()
order by id desc' 
END
GO
GRANT EXECUTE ON [dbo].[GetCDEMannounce] TO [public]

Open in new window

0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24408353
run this instead.

ALTER procedure [dbo].[GetCDEMannounce]
as
select FullItem
from dbo.CDEMAnnounce
where StartDate <= getDate()--dateadd(d,-1,getDate())
      and ExpireDate > getDate()
order by id desc

GO
GRANT EXECUTE ON [dbo].[GetCDEMannounce] TO [public]

0
 
LVL 29

Author Comment

by:QPR
ID: 24408777
yep, I do... by ignoring all the other text in the modify dialogue and just selecting/running the actual alter procedure statement.

But why?
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 24408785
because that is how it should be done...I wish I knew why MS decided it was a better idea to generate dynamic SQL when you use an IF object exists clause...you can go to tools, options, and turn that option off.  If you don't use the option to drop the object if it exists, it doesn't use the dynamic sql
0
 
LVL 29

Author Comment

by:QPR
ID: 24408856
Can I clarify unless I'm missing something...
I navigate to the SP in SSMS, right click and choose modify.
Amend the text and then execute. Get the message that the command ran successfully.
But in reality the changes were not made/saved and the changed have not propogated to the DB?
0
 
LVL 29

Author Comment

by:QPR
ID: 24408868
sorry the "but why" was not directed at your uiggestion, it was directed at why would MS give me this "modify" option that doesn't appear to work.
0
 
LVL 29

Author Closing Comment

by:QPR
ID: 31582425
that works (changing the options) thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

762 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