Oct 23, 2013

How to compile any query without executing it in sql server

In sql server we can compile any sql server quires without executing it by setting the property NOEXEC.
Syntax:
SET NOEXEC {ON|OFF}
When It is set to on then if we execute any sql quries it will only compile it while if it is set to off then it will compile the sql quries as will execute it. Default is off. For example:
SET NOEXEC OFF
SELECT 'Exact Help'

Output: Exact Help
When we will execute the above query first it will compile then execute it .

SET NOEXEC ON
SELECT 'Exact Help'
Output: No output.
When we will execute the above query it will only compile.

Use of NOEXEC ON
1. To check the synax of sql statements.
2. To check the existance of objects.
3. To debug the batch of quries.
Scope of NOEXEC property:
Scope of NOEXEC property is within a session. In other session we have to set the NOEXEC property once again.

No comments:

Post a Comment