What is SET NOEXEC ON in the T-SQL statement?

Do you want to compile the query without executing it? If yes, you can use SET NOEXEC ON at the beginning of the T-SQL statement.


In SQL Server, there are two ways to compile a query. The first is to compile a query by executing it, and the second is to compile a query without executing it. This blog shows you how to compile a query without executing it.


The default setting is SET NOEXEC OFF, which returns the query result once we run it.


Let's execute the below code that uses default configuration - SET NOEXEC OFF


--DEFAULT SET NOEXEC OFF
SELECT COUNT(*) AS CountofSales
FROM SalesLT.SalesOrderHeader

Default SET NOEXEC OFF

As shown below, with the statement SET NOEXEC ON, we do not get query output. SQL Server compiles the query for any syntax or object names without executing it.


SET NOEXEC ON
SELECT COUNT(*) AS CountofSales
FROM SalesLT.SalesOrderHeader

SQL Server only compiles query using SET NOEXEC ON

16 views0 comments