Transact SQL:- Set Commands – Set ParseOnly On

Background

I was trying to place constraints around executing a SQL Statement.

Tried using “set parseonly on“.

 

Code

Outline

  1. Reset environment
    • set parseonly off
  2. Conditional
    • If 1=0
      • set parseonly on
  3. Reset environment
    • set parseonly off

SQL



set parseonly off
go

print 'Step 1 - Pre - Set ParseOnly On'
go

if ( 1=0)
begin

    print char(9) + 'Pre - Set parseonly on ....'

    set parseonly on

    print char(9) + 'Post - Set Parseonly on set to on'

end
go


print 'Step 2 - Post - Set ParseOnly On'
go

set parseonly off
go

print 'Step 3 - Post - Set ParseOnly Off'
go

Output

Image

Text


Step 1 - Pre - Set ParseOnly On
Step 3 - Post - Set ParseOnly Off

Source Code Control

GitLab

  1. SQL Server – Transact SQL – Set Statement
    Link

Summary

There is nothing conditional about “set parseonly“.

When “set parseonly on” is encountered, SQL parsing continues.

But, none of the successive SQL Statements are executed thereafter.

That is “ParseOnly” is really what it says.

Parse successive statements, but do not execute them.

Set parseonly off” will re-enable execution.

 

References

  1. Microsoft
    • Learn / SQL / SQL Server
      • SET PARSEONLY (Transact-SQL)
        Link

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s