title: Why do we use the SET NOCOUNT ON; along with the SELECT @@ROWCOUNT;?
body: <p>I am learning through the EF Core through the tutorials over <a href="https://www.learnentityframeworkcore.com/relationships/managing-one-to-many-relationships" rel="nofollow noreferrer">here</a> and I come across the following statements being used in the examples of the T-SQL queries:</p>
  
  <p>1 <code>SET NOCOUNT ON;</code> Meaning (from <a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/set-nocount-transact-sql?view=sql-server-ver15" rel="nofollow noreferrer">here</a>): </p>
  
  <blockquote>
    <p>Stops the message that shows the count of the number of rows affected by a Transact-SQL statement or stored procedure from being returned as part of the result set.</p>
  </blockquote>
  
  <p>2 <code>SELECT @@ROWCOUNT;</code> Meaning (from <a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/rowcount-transact-sql?view=sql-server-ver15" rel="nofollow noreferrer">here</a>)</p>
  
  <blockquote>
    <p>Returns the number of rows affected by the last statement.</p>
  </blockquote>
  
  <p>The 1 and 2 are used simultaneously. And that is confusing for me. For instance, here:</p>
  
  <pre><code>exec sp_executesql N'SET NOCOUNT ON;
  UPDATE [Books] SET [AuthorId] = @p0
  WHERE [BookId] = @p1;
  SELECT @@ROWCOUNT;
  ',N'@p1 int,@p0 int',@p1=4,@p0=1
  </code></pre>
  
  <p>I can not understand why would someone want to turn off the effect of the 2 with the help of 1 if it is possible to avoid the effect of the 2 by just not adding it into the query. I.e. the following query will do exactly the same as the above one:</p>
  
  <pre><code>exec sp_executesql N'UPDATE [Books] SET [AuthorId] = @p0
  WHERE [BookId] = @p1;
  ',N'@p1 int,@p0 int',@p1=4,@p0=1
  </code></pre>
  
  <p>Am I missing something here or what is the purpose of using both the <code>SET NOCOUNT ON</code> and the <code>SELECT @@ROWCOUNT</code> simultaneously?</p>