Solved

sp_recompile

Posted on 1997-11-11
2
554 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 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

731 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