Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
swissivan
Starting Member
30 Posts |
Posted - 2013-02-26 : 22:08:47
|
My objective is to update two tables in the same time and make sure the data is in sync.Real Case : Customer buy a product, system will create a record in ProductTransaction and then update balance of that product in another table ProductBalance.I would like to know is it using transaction rollback as below is really safe? thanks. BEGIN TRANSACTIONINSERT INTO ProductTransaction ....IF @@ERROR <> 0 BEGIN ROLLBACK RAISERROR ('Error when insert ProductTransaction.', 16, 1) RETURNENDUPDATE ProductBalance ....IF @@ERROR <> 0 BEGIN ROLLBACK RAISERROR ('Error when update TableB.', 16, 1) RETURNENDCOMMIT |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-26 : 22:42:27
|
why not use TRY CATCH?http://msdn.microsoft.com/en-in/library/ms179296(v=sql.105).aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
swissivan
Starting Member
30 Posts |
Posted - 2013-02-26 : 23:00:44
|
quote: Originally posted by visakh16 why not use TRY CATCH?http://msdn.microsoft.com/en-in/library/ms179296(v=sql.105).aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I am new to store procedure, could you please explain the pros and cons of .NET Try Catch VS Store Procedure Rollback? Many thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-26 : 23:04:09
|
quote: Originally posted by swissivan
quote: Originally posted by visakh16 why not use TRY CATCH?http://msdn.microsoft.com/en-in/library/ms179296(v=sql.105).aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I am new to store procedure, could you please explain the pros and cons of .NET Try Catch VS Store Procedure Rollback? Many thanks.
its not .NET TRy CatchRefer the article. It speaks of T-SQL TRY CATCH you can use in stored procedure itself.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
swissivan
Starting Member
30 Posts |
Posted - 2013-02-27 : 02:21:13
|
quote: Originally posted by visakh16
quote: Originally posted by swissivan
quote: Originally posted by visakh16 why not use TRY CATCH?http://msdn.microsoft.com/en-in/library/ms179296(v=sql.105).aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I am new to store procedure, could you please explain the pros and cons of .NET Try Catch VS Store Procedure Rollback? Many thanks.
its not .NET TRy CatchRefer the article. It speaks of T-SQL TRY CATCH you can use in stored procedure itself.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Sorry about the missundestanding, just read a paper about .net vs store procedure.Try Catch works great. Thank you very much. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-27 : 04:10:33
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|