Background
I was trying to place constraints around executing a SQL Statement.
Tried using “set parseonly on“.
Code
Outline
- Reset environment
- set parseonly off
- Conditional
- If 1=0
- set parseonly on
- If 1=0
- 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
- 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
- Microsoft
- Learn / SQL / SQL Server
- SET PARSEONLY (Transact-SQL)
Link
- SET PARSEONLY (Transact-SQL)
- Learn / SQL / SQL Server