From the course: Complete Guide to Advanced SQL Server
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Manage transaction control - SQL Server Tutorial
From the course: Complete Guide to Advanced SQL Server
Manage transaction control
We've seen a number of techniques for managing the flow of a program using error handling with TRY-CATCH blocks. Now, it's time to combine that with what we learned in the previous chapter about transactions. If you remember, we saw that transactions need to be closed by either finalizing the data with commit transaction or undoing the changes with rollback transaction. But in that chapter, we had to manually decide which route to take and either send the commit command or the rollback command ourselves. The last piece of that puzzle is to combine all of this knowledge and have the TRY-CATCH blocks control when a commit is sent and when a rollback is sent. So let's go back to the prior transaction example. When we last saw the Warehouse.Colors table, we had just inserted a row called Burnished Bronze. We also wrote this transaction on Lines 11 through 16. This transaction is used to insert two new colors and then commit the change to the table all at once. But we found that if you try…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
What is error handling?1m 52s
-
(Locked)
Capture errors with TRY and CATCH4m 54s
-
(Locked)
Generate errors with THROW4m 12s
-
(Locked)
Manage transaction control4m 4s
-
(Locked)
Challenge: Add error handling to a stored procedure1m 12s
-
(Locked)
Solution: Add error handling to a stored procedure12m 12s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-