Solved

Modifiying an SP

Posted on 2009-05-17
10
221 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
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Title # Comments Views Activity
SQL Merige returns error code when updating 15 53
Help with simplifying SQL 6 53
user defined date datatype in SQL Server- can it be overdone.. 6 32
SQL Error - Query 6 24
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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