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. adding SET NOCOUNT ON to large number of stored procedures [modified]

adding SET NOCOUNT ON to large number of stored procedures [modified]

Scheduled Pinned Locked Moved Database
databasequestion
12 Posts 5 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.
  • T T2102

    What's a good way to modify a large number of stored procedures? I took over a project that is not using SET NOCOUNT ON, i.e. the following query returns several hundred rows. SELECT Distinct SO.Name, SC.TEXT FROM sysobjects SO (NOLOCK) INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID AND SO.Type = 'P' AND SC.colid=1 --multiple colid's are utilized when the procedures text is very long AND NOT UPPER(SC.TEXT) LIKE '%SET NOCOUNT ON%' ORDER BY SO.Name

    modified on Friday, November 27, 2009 2:17 AM

    V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #2

    hi Ted SET NOCOUNT ON is used if you dont want to show results. Lets say i have a Query that Updates a Table, at the end it will give me something like

    100 Rows Affected

    to make sure that the update does not show that message , you use SET NOCOUNT ON i have never seen this use in a query passed as a parameter, am not sure if this is correct because as i remember correctly you are not supposed to do that. mybe you can explain your challenge clearly and we can suggest another option

    Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

    T 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      hi Ted SET NOCOUNT ON is used if you dont want to show results. Lets say i have a Query that Updates a Table, at the end it will give me something like

      100 Rows Affected

      to make sure that the update does not show that message , you use SET NOCOUNT ON i have never seen this use in a query passed as a parameter, am not sure if this is correct because as i remember correctly you are not supposed to do that. mybe you can explain your challenge clearly and we can suggest another option

      Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

      T Offline
      T Offline
      T2102
      wrote on last edited by
      #3

      I wanted to add SET NOCOUNT ON in the body of the stored procedure after AS. I am relatively new to SQL Server (I used Oracle before) and the articles I read on google suggested that you should always SET NOCOUNT ON before executing queries inside a stored procedure.

      V 1 Reply Last reply
      0
      • T T2102

        I wanted to add SET NOCOUNT ON in the body of the stored procedure after AS. I am relatively new to SQL Server (I used Oracle before) and the articles I read on google suggested that you should always SET NOCOUNT ON before executing queries inside a stored procedure.

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #4

        then the correct way to do it is the Following

        Create Proc myprc
        as

        set nocount on

        --Do what Ever and set it back to off

        set nocount off

        Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

        S 1 Reply Last reply
        0
        • V Vimalsoft Pty Ltd

          then the correct way to do it is the Following

          Create Proc myprc
          as

          set nocount on

          --Do what Ever and set it back to off

          set nocount off

          Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #5

          That's not what was asked, he knows how to set nocount on. He wants to know if there is a way to easily modify all of his stored procedures to include this line.

          V 1 Reply Last reply
          0
          • S ScottM1

            That's not what was asked, he knows how to set nocount on. He wants to know if there is a way to easily modify all of his stored procedures to include this line.

            V Offline
            V Offline
            Vimalsoft Pty Ltd
            wrote on last edited by
            #6

            I must have misunderstood him , No there is no way even SQL Compare wouldnt do that

            Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

            1 Reply Last reply
            0
            • T T2102

              What's a good way to modify a large number of stored procedures? I took over a project that is not using SET NOCOUNT ON, i.e. the following query returns several hundred rows. SELECT Distinct SO.Name, SC.TEXT FROM sysobjects SO (NOLOCK) INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID AND SO.Type = 'P' AND SC.colid=1 --multiple colid's are utilized when the procedures text is very long AND NOT UPPER(SC.TEXT) LIKE '%SET NOCOUNT ON%' ORDER BY SO.Name

              modified on Friday, November 27, 2009 2:17 AM

              S Offline
              S Offline
              ScottM1
              wrote on last edited by
              #7

              You could perhaps do this using a cursor with sysobjects and sp_helptext. You would use the cursor to step through "select name from sysobjects where xtype = 'P'". You could then get the stored procedure using sp_helptext and modify it and execute accordingly.

              D T 2 Replies Last reply
              0
              • S ScottM1

                You could perhaps do this using a cursor with sysobjects and sp_helptext. You would use the cursor to step through "select name from sysobjects where xtype = 'P'". You could then get the stored procedure using sp_helptext and modify it and execute accordingly.

                D Offline
                D Offline
                David Skelly
                wrote on last edited by
                #8

                Or you could go to your version control system, check out the scripts for the stored procedures, modify them as required (using a little noddy program to automate the process), test them, check them back in again and then re-run them to drop and recreate the stored procedures in the target database. Oh, dear. No scripts.

                S 1 Reply Last reply
                0
                • D David Skelly

                  Or you could go to your version control system, check out the scripts for the stored procedures, modify them as required (using a little noddy program to automate the process), test them, check them back in again and then re-run them to drop and recreate the stored procedures in the target database. Oh, dear. No scripts.

                  S Offline
                  S Offline
                  ScottM1
                  wrote on last edited by
                  #9

                  But that would be too easy. :)

                  1 Reply Last reply
                  0
                  • T T2102

                    What's a good way to modify a large number of stored procedures? I took over a project that is not using SET NOCOUNT ON, i.e. the following query returns several hundred rows. SELECT Distinct SO.Name, SC.TEXT FROM sysobjects SO (NOLOCK) INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID AND SO.Type = 'P' AND SC.colid=1 --multiple colid's are utilized when the procedures text is very long AND NOT UPPER(SC.TEXT) LIKE '%SET NOCOUNT ON%' ORDER BY SO.Name

                    modified on Friday, November 27, 2009 2:17 AM

                    G Offline
                    G Offline
                    Giorgi Dalakishvili
                    wrote on last edited by
                    #10

                    You can use SMO to generate scripts add the statement you need and execute the script.

                    Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

                    T 1 Reply Last reply
                    0
                    • S ScottM1

                      You could perhaps do this using a cursor with sysobjects and sp_helptext. You would use the cursor to step through "select name from sysobjects where xtype = 'P'". You could then get the stored procedure using sp_helptext and modify it and execute accordingly.

                      T Offline
                      T Offline
                      T2102
                      wrote on last edited by
                      #11

                      Thanks. I think sp_helptext will do the trick. I also will take a look at SMO, which was suggested by another helpful programmer.

                      1 Reply Last reply
                      0
                      • G Giorgi Dalakishvili

                        You can use SMO to generate scripts add the statement you need and execute the script.

                        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

                        T Offline
                        T Offline
                        T2102
                        wrote on last edited by
                        #12

                        I just found out that there is SQL Server Options -> Query Execution -> Advanced has the option to set NOCOUNT

                        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