Sample MySQL transaction ROLLBACK code

Source: Internet
Author: User
No detailed content transaction ROLLBACKMySQLmysqlmysqldelimiter $ mysqlmysqlCREATEPROCEDUREmyProc (

No details transaction ROLLBACK MySQL mysqlmysql delimiter $ mysqlmysql create procedure myProc (-in_from INTEGER,-in_to INTEGER,-in_amount DECIMAL ()-BEGIN-DECLARE txn_error integer default 0; --DECLARE CONTINUE HANDLER FOR SQLEX

<无详细内容> Transaction ROLLBACK MySQL
mysql>mysql> delimiter $$mysql>mysql> CREATE PROCEDURE myProc(    ->   in_from INTEGER,    ->   in_to   INTEGER,    ->   in_amount DECIMAL(8,2))    -> BEGIN    ->    ->   DECLARE txn_error INTEGER DEFAULT 0 ;    ->    ->   DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN    ->     SET txn_error=1;    ->   END;    ->    ->   SAVEPOINT savepoint_tfer;    ->    ->   UPDATE employee    ->      SET salary=in_amount    ->    WHERE id=in_from;    ->    ->   IF txn_error THEN    ->     ROLLBACK TO savepoint_tfer;    ->     SELECT 'Transfer aborted ';    ->   ELSE    ->     UPDATE employee    ->        SET salary=in_amount    ->      WHERE id=in_to;    ->    ->      IF txn_error THEN    ->         ROLLBACK TO savepoint_tfer;    ->         SELECT 'Transfer aborted ';    ->      END IF;    ->   END IF;    ->    -> END$$Query OK, 0 rows affected (0.00 sec)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.