HiveBrain v1.2.0
Get Started
← Back to all entries
gotchasqlMinor

What is the difference between SET NOEXEC ON and SET PARSEONLY ON?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thewhatandparseonlydifferencebetweennoexecset

Problem

Currently, SQL server supports the following statements: SET NOEXEC and SET PARSEONLY.

From the documentation:

SET NOEXEC ON:

When SET NOEXEC is ON, SQL Server compiles each batch of Transact-SQL statements but does not execute them.

SET PARSEONLY ON:

When SET PARSEONLY is ON, SQL Server only parses the statement.

I guess it's "compiles" vs. "parses". "Compiles" should include "parses".

If I want to verify the correctness of SQL Scripts which one should I use? I am inclined to answer: SET NOEXEC ON.

But what else does compile do? Does "compile" mean the execution plans are created/modified? Is the existence of objects checked?

What happens if you have:

SET NOEXEC ON
SET PARSEONLY OFF


I find having both options available confusing.

Thanks

Solution

There are three steps to running a batch:

  • Parse



  • Compile



  • Execute



PARSEONLY stops after step 1). NOEXEC stops after step 2), with the exception that NOEXEC supports deferred name resolution and won't fail if the target tables don't exist.

When SET NOEXEC is ON, SQL Server compiles each batch of Transact-SQL
statements but does not execute them.

NOEXEC

When SET PARSEONLY is ON, SQL Server only parses the statement. When
SET PARSEONLY is OFF, SQL Server compiles and executes the statement.

PARSEONLY

Context

StackExchange Database Administrators Q#270503, answer score: 8

Revisions (0)

No revisions yet.