Note that there are some explanatory texts on larger screens.

plurals
  1. POInteresting behavior in "NOEXEC ON"
    primarykey
    data
    text
    <p>While I was writing some T-SQL queries with <code>NOEXEC ON</code>, I experienced interesting behavior of SQL Server and I am curious about why it happened. Sometimes I got only </p> <blockquote> <p>Command(s) successfully.</p> </blockquote> <p>message as I expected, but sometimes I got one or more </p> <blockquote> <p>(0 row(s) affected)</p> </blockquote> <p>messages.</p> <p>I know that <code>SET NOEXEC ON</code> command compiles query but does not execute it, so I think I should not gotten any </p> <blockquote> <p>(0 row(s) affected)</p> </blockquote> <p>messages.</p> <p>In the first example, everything looks normal.</p> <pre><code>SET NOEXEC ON INSERT INTO Test (column1) VALUES ('etc') </code></pre> <p>Result:</p> <blockquote> <p>Command(s) successfully.</p> </blockquote> <p>But in the second example, I think something goes wrong...</p> <pre><code>SET NOEXEC ON DELETE FROM Test </code></pre> <p>Result:</p> <blockquote> <p>(0 row(s) affected)</p> </blockquote> <p>In the third example I used temp table:</p> <pre><code>CREATE TABLE #tmp (id INT IDENTITY(1, 1), idX INT) SET NOEXEC ON INSERT INTO #tmp (idX) VALUES (1) DELETE FROM Test SET NOEXEC OFF DROP TABLE #tmp </code></pre> <p>Result:</p> <blockquote> <p>(0 row(s) affected)</p> </blockquote> <p>And finally I added only <code>GO</code> to my query, I think result is interesting</p> <pre><code>CREATE TABLE #tmp (id INT IDENTITY(1, 1), idX INT) SET NOEXEC ON GO INSERT INTO #tmp (idX) VALUES (1) DELETE FROM Test SET NOEXEC OFF DROP TABLE #tmp </code></pre> <p>Result:</p> <blockquote> <p>(0 row(s) affected)</p> <p>(0 row(s) affected)</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload