Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SET NOCOUNT ON;

SET NOCOUNT ON;

Scheduled Pinned Locked Moved Database
databasesql-serversysadminperformancequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    geekfromindia
    wrote on last edited by
    #1

    As we know that "Set NoCount ON;" increases the performance in SQL server queries by avoiding any extramessages being sent to client... We are using this statement invarialbly in all procedures and I have seen it being part of SQL Server default procedure template... What I couldnt figure out is if we need to use this with all the statements why is it OFF by default??? What are the cases where we shouldn't be using it???

    ~AHAGeek

    J M 2 Replies Last reply
    0
    • G geekfromindia

      As we know that "Set NoCount ON;" increases the performance in SQL server queries by avoiding any extramessages being sent to client... We are using this statement invarialbly in all procedures and I have seen it being part of SQL Server default procedure template... What I couldnt figure out is if we need to use this with all the statements why is it OFF by default??? What are the cases where we shouldn't be using it???

      ~AHAGeek

      J Offline
      J Offline
      Jon_Boy
      wrote on last edited by
      #2

      A _sp that returns a result set and you want the count (often for queries and reporting purposes).

      Any suggestions, ideas, or 'constructive criticism' are always welcome.

      G 1 Reply Last reply
      0
      • J Jon_Boy

        A _sp that returns a result set and you want the count (often for queries and reporting purposes).

        Any suggestions, ideas, or 'constructive criticism' are always welcome.

        G Offline
        G Offline
        geekfromindia
        wrote on last edited by
        #3

        In SP if we want count..we can still use @@RowCount with this statement on???

        ~AHAGeek

        J 1 Reply Last reply
        0
        • G geekfromindia

          In SP if we want count..we can still use @@RowCount with this statement on???

          ~AHAGeek

          J Offline
          J Offline
          Jon_Boy
          wrote on last edited by
          #4

          Typically I would use @@ROWCOUNT in a stored procedure where there are several transactions that are going to modify records. You can then be certain that every update, delete, insert occurs as expected; esp. in stored procedures where it's all or nothing. If 1 table doesn't get modified as expected, you can then rollback. IE: You have a SP (with NOCOUNT = ON) that has several table updates for updating general ledger entries for A/R and then write the changes into a history table. If one update fails (by checking @@ROWCOUNT), the entire transaction gets rolled. Returning a rowcount (meaning NOCOUNT = OFF) is good for a very simple sps that return a result set and the row count can be displayed for information purposes and ensure the query didn't error off.

          Any suggestions, ideas, or 'constructive criticism' are always welcome.

          1 Reply Last reply
          0
          • G geekfromindia

            As we know that "Set NoCount ON;" increases the performance in SQL server queries by avoiding any extramessages being sent to client... We are using this statement invarialbly in all procedures and I have seen it being part of SQL Server default procedure template... What I couldnt figure out is if we need to use this with all the statements why is it OFF by default??? What are the cases where we shouldn't be using it???

            ~AHAGeek

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            I suggest the default is bc it is useful when coding a proc, it is only when you go to production that you want to turn it off. It would be nice to be able to turn it off as a database/server option.

            Never underestimate the power of human stupidity RAH

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups