I have the following code:
-- start of code
set noexec off
declare @requiredVersion int
declare @currentVersion int
set @requiredVersion = 5
set @currentVersion = 4
if (@currentVersion < @requiredVersion)
begin
print 'Please update your DB to version 5 before running this script.'
set noexec on
end
go
-- print 'Dummy'
insert into tblFooBar(name) values ('AAA')
go
set noexec off
-- end of code
Please note that table "tblfoobar" does not exists in the database. When I run this code, the message comes up:
Please update your DB to version 5 before running this script. Msg 208, Level 16, State 1, Line 1 Invalid object name 'tblFooBar'.
I was expecting that setting up noexec to ON may not give the "Msg 208" part of the message.
Then again "set noexec on" compiles the code, does not execute it. Trying to insert something into a table that does not exists is a compile-time error - I am guessing. If that is the case, then the error about "missing object" should come up.
Now let me tell you the strange behaviour I have observed. If I remove the comment from the line "-- Print 'dummy'"
-- start of code
set noexec off
declare @requiredVersion int
declare @currentVersion int
set @requiredVersion = 5
set @currentVersion = 4
if (@currentVersion < @requiredVersion)
begin
print 'Please update your DB to version 5 before running this script.'
set noexec on
end
go
print 'Dummy'
insert into tblFooBar(name) values ('AAA')
go
and execute the code, I only get the following message.
Please update your DB to version 5 before running this script.
This time there is no message about missing table.
Can someone please explain this behaviour to me? Thanks.