Stored Procedure Transaction

后端 未结 2 771
梦谈多话
梦谈多话 2021-02-04 04:29

I have never used a Transaction, Commit and Rollback before and now I need to use one. I have checked around online, etc for examples to make sure that I am in fact using this

2条回答
  •  遥遥无期
    2021-02-04 05:20

    First, databases are fairly reliable. And if they fail, you have a bigger problem than handling individual transactions. So my feedback would be that you have too much error checking for a simple transaction. A failing insert is such an unusual event that you normally wouldn't write code to handle it.

    Second, this code won't actually "catch" errors:

    IF @ErrorCode <> 0
    

    An error in the SQL statement will abort the stored procedure and return to the client. You'd have to try ... catch to actually handle an error in a stored procedure.

    Third, I try to avoid raiserr. It can do unexpected things both on the server and the client side. Instead, consider using an output parameter to return error information to the client program.

提交回复
热议问题