• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How can i rollback everything if one update fails?

Resolved: How can i rollback everything if one update fails?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

So i want to check if can update the table RegEnfermeiro (if not then rollback), if it can update then checks if can update the table RegEnfAtiv, if it fails rollback this one and the RegEnfemeiro, and the process continous to the next one. I thought this would works but it doesnt. Can someone explain how can i make this works?
”’

Answer:

You would be better off using XACT_ABORT here. From the documentation:

When SET XACT_ABORT is ON, if a Transact-SQL statement raises a run-time error, the entire transaction is terminated and rolled back.


This’ll mean that if one statement in the procedure fails, all the statements will be rolled back:
db<>fiddle example

If you have better answer, please add a comment about this, thank you!

sql-server stored-procedures
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to give rank on datetime column group by another column with userid in it

24/03/2023

Resolved: Passing 2 functions in onChange in react

24/03/2023

Resolved: Why doesn’t stringstream consume output during hex formatting?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.