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. SQL Server 2008: Will the stored procedure be rolled back if the db server gets an error (server crash or performance problem) in the middle of it's operation?

SQL Server 2008: Will the stored procedure be rolled back if the db server gets an error (server crash or performance problem) in the middle of it's operation?

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadminperformance
7 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.
  • R Offline
    R Offline
    Rafferty Uy
    wrote on last edited by
    #1

    This is for SQL Server 2008: Will the stored procedure be rolled back if the db server gets an error (server crash or performance problem) in the middle of it's operation? This is the idea: - stored proc spTest contains 2 insert statements - exec spTest - spTest executes 1st insert statement - stored procedure still running... but server gets some problem that's unrelated to this stored procedure, which causes the stored proc to stop (e.g. server crash) Will the data in the 1st insert statement be rolled back? Thanks in advance!

    Rafferty

    P L 2 Replies Last reply
    0
    • R Rafferty Uy

      This is for SQL Server 2008: Will the stored procedure be rolled back if the db server gets an error (server crash or performance problem) in the middle of it's operation? This is the idea: - stored proc spTest contains 2 insert statements - exec spTest - spTest executes 1st insert statement - stored procedure still running... but server gets some problem that's unrelated to this stored procedure, which causes the stored proc to stop (e.g. server crash) Will the data in the 1st insert statement be rolled back? Thanks in advance!

      Rafferty

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      If you want it to be.

      R 1 Reply Last reply
      0
      • P PIEBALDconsult

        If you want it to be.

        R Offline
        R Offline
        Rafferty Uy
        wrote on last edited by
        #3

        What do you mean? Currently, these 2 insert statements are not enclosed in try catch blocks, but I didn't think that I need to because the error is caused by something else that is external to this stored procedure. Or is there some DB configuration-wide that I should set?

        Rafferty

        1 Reply Last reply
        0
        • R Rafferty Uy

          This is for SQL Server 2008: Will the stored procedure be rolled back if the db server gets an error (server crash or performance problem) in the middle of it's operation? This is the idea: - stored proc spTest contains 2 insert statements - exec spTest - spTest executes 1st insert statement - stored procedure still running... but server gets some problem that's unrelated to this stored procedure, which causes the stored proc to stop (e.g. server crash) Will the data in the 1st insert statement be rolled back? Thanks in advance!

          Rafferty

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Rafferty Uy wrote:

          Will the data in the 1st insert statement be rolled back?

          How about wrapping them both in a single transaction[^].

          I are Troll :suss:

          R 1 Reply Last reply
          0
          • L Lost User

            Rafferty Uy wrote:

            Will the data in the 1st insert statement be rolled back?

            How about wrapping them both in a single transaction[^].

            I are Troll :suss:

            R Offline
            R Offline
            Rafferty Uy
            wrote on last edited by
            #5

            Hi Eddy, thanks for answering. I understand that it's better to wrap both in a single transaction. My question is really what happens if i don't. I want to know the normal behavior of sql server in such a case, not how I can improve the code. I'm investigating a bug and I suspect that this was the cause of the problem... but it seems far fetched because the server didn't crash... it just experienced some performance issues. Thanks again!

            Rafferty

            L 1 Reply Last reply
            0
            • R Rafferty Uy

              Hi Eddy, thanks for answering. I understand that it's better to wrap both in a single transaction. My question is really what happens if i don't. I want to know the normal behavior of sql server in such a case, not how I can improve the code. I'm investigating a bug and I suspect that this was the cause of the problem... but it seems far fetched because the server didn't crash... it just experienced some performance issues. Thanks again!

              Rafferty

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Rafferty Uy wrote:

              My question is really what happens if i don't.

              It will write up to the point of the crash, and execution will halt. No automatic recovery, If it crashes midway, the first sproc might be saved, the second might not. If it crashes during a write-operation, your entire database might become corrupt.

              I are Troll :suss:

              R 1 Reply Last reply
              0
              • L Lost User

                Rafferty Uy wrote:

                My question is really what happens if i don't.

                It will write up to the point of the crash, and execution will halt. No automatic recovery, If it crashes midway, the first sproc might be saved, the second might not. If it crashes during a write-operation, your entire database might become corrupt.

                I are Troll :suss:

                R Offline
                R Offline
                Rafferty Uy
                wrote on last edited by
                #7

                Just the answer I'm looking for! Thanks a lot Eddy! This really helped :)

                Rafferty

                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