Error Handling of nested transactions and transaction retention points
For nested transactions.1. Start external transactions, start internal transactions, and try catchInternal error: if an internal transaction error occurs, internal and
TRY ... Catch is an impressive new feature of SQL Server 2005/2008. Improved developer exception handling. There is no reason not to try. Catch function.
* TRY block-Contains code or script that may produce an exception* Catch Block-If an exception
Original: http://www.cnblogs.com/yun_shuai/archive/2010/09/20/1831546.html/*1. Minor error (Severity level 0-10): By default, the client program is not sent an error message to continue working. Which means it can't be caught in a catch.2. Medium
The code examples in many books use try catch in database access functions to mislead beginners.
Let's analyze a common function (Some large companies in ChinaCode, negative examples, cannot be imitated),
1 public int updateData(String sql)
CREATE PROCEDURE YourprocedureAsBEGINSET NOCOUNT on;Begin TRY---------------------Start catching exceptionsBEIN TRAN------------------Start a transactionUPDATE A SET a.names = b.names from table 1 as A INNER JOIN table 2 as B on a.id = b.IDUPDATE A
Try catch in SQL The code is as follows:Copy code BEGIN TRANSACTIONBEGIN TRY-- YOUR SQLCOMMITEND TRYBEGIN CATCHROLLBACKEND CATCH The above code is executed in SQL SERVER 2008.After try catch is used, the CATCH will be rolled back if an
In spring transaction control, the principle of exception trigger transaction rollback is discussed. The article has 6 scenarios in which spring transactions are rolled back.The following code is based on spring-and-mybatis consolidation, using the
begin Try -- endbegin--SQL (handle error action)end CatchWe're going to write the SQL that might go wrong between the begin try...end try, and if something goes wrong, just the program jumps to the beign catch...end catch immediately following the
BeginTry--sqlEndTrybeginCatch--sql (handle error action) endCatchWe're going to write a possible error in SQL at begin Try...endIf there is an error between the try, the program jumps to the immediately following begin Try...endBeign Catch...end of
Begin Try -- SQL End Try Begin Catch -- SQL (handling error Actions) End CatchWe will write the SQL statements that may cause errors in begin try... End If an error occurs between try and try Program Jump to the next begin try... End Try
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.