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
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.