Link to home
Start Free TrialLog in
Avatar of sajalk
sajalk

asked on

sp_recompile

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.
ASKER CERTIFIED SOLUTION
Avatar of bret
bret
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sajalk
sajalk

ASKER

i did see the answer under the alter table documentation as bret mentioned.
thanx a lot.