?
Solved

sp_recompile

Posted on 1997-11-11
2
Medium Priority
?
562 Views
Last Modified: 2010-05-18
here is what i did:
create table Sajal (ID int)
insert Sajal values (1)
create procedure Sajal1 as
   insert Sajal values (1)
exec Sajal1
select * from Sajal   yields 1 row with value 1 in it.
alter table Sajal Add ModUser varchar(5) null
sp_recompile Sajal
gives the following message which is what one would expect:
Each stored procedure and trigger that uses table Sajal
will be recompiled the next time it is executed.
exec Sajal1
i was expecting that the above step would fail as now the table structure has been changed, since sp_recompile step would make sure that
the procedure is recompiled when invoked. however, the procedure excutes fine with a row in the table Sajal 1 null for ID and ModUser.
on the other hand when i execute the following:
create procedure Sajal1 as
insert Sajal values (1)
it complains that the number of columns in the table Sajal does not match with the number of values provided.

my question is that even after sp_recompile why does it not take into account the latest state of the objects that the procedure is referencing when one does exec Sajal1?
need help.
thanx.
sajal.
0
Comment
Question by:sajalk
[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
2 Comments
 
LVL 10

Accepted Solution

by:
bret earned 200 total points
ID: 1089102
Because sp_recompile does not truly completely recompile the stored procedure, it is more a matter of "reoptimizing" it.  sp_recompile does cause new indexes, etc to be considered, but the procedure still doesn't realize changes to the actual table structure.  Only dropping and recreating the entire procedure does that.

I seem to recall that this is documented under the "alter table" command.

-bret


0
 

Author Comment

by:sajalk
ID: 1089103
i did see the answer under the alter table documentation as bret mentioned.
thanx a lot.
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

800 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