Solved

sp_recompile

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now