Solved

sp_recompile

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

839 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