• <tfoot id='OauDO'></tfoot>
    1. <legend id='OauDO'><style id='OauDO'><dir id='OauDO'><q id='OauDO'></q></dir></style></legend>
        <i id='OauDO'><tr id='OauDO'><dt id='OauDO'><q id='OauDO'><span id='OauDO'><b id='OauDO'><form id='OauDO'><ins id='OauDO'></ins><ul id='OauDO'></ul><sub id='OauDO'></sub></form><legend id='OauDO'></legend><bdo id='OauDO'><pre id='OauDO'><center id='OauDO'></center></pre></bdo></b><th id='OauDO'></th></span></q></dt></tr></i><div id='OauDO'><tfoot id='OauDO'></tfoot><dl id='OauDO'><fieldset id='OauDO'></fieldset></dl></div>

        • <bdo id='OauDO'></bdo><ul id='OauDO'></ul>

        <small id='OauDO'></small><noframes id='OauDO'>

        mysql 事务 - 回滚任何异常

        mysql transaction - roll back on any exception(mysql 事务 - 回滚任何异常)
          <tbody id='GVe1s'></tbody>
        <i id='GVe1s'><tr id='GVe1s'><dt id='GVe1s'><q id='GVe1s'><span id='GVe1s'><b id='GVe1s'><form id='GVe1s'><ins id='GVe1s'></ins><ul id='GVe1s'></ul><sub id='GVe1s'></sub></form><legend id='GVe1s'></legend><bdo id='GVe1s'><pre id='GVe1s'><center id='GVe1s'></center></pre></bdo></b><th id='GVe1s'></th></span></q></dt></tr></i><div id='GVe1s'><tfoot id='GVe1s'></tfoot><dl id='GVe1s'><fieldset id='GVe1s'></fieldset></dl></div>

        <small id='GVe1s'></small><noframes id='GVe1s'>

        1. <tfoot id='GVe1s'></tfoot>

            <bdo id='GVe1s'></bdo><ul id='GVe1s'></ul>

              <legend id='GVe1s'><style id='GVe1s'><dir id='GVe1s'><q id='GVe1s'></q></dir></style></legend>
                • 本文介绍了mysql 事务 - 回滚任何异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  如果mysql命令列表出现任何错误,是否可以自动回滚?

                  Is it possible to roll back automatically if any error occurs on a list of mysql commands?

                  例如:

                  begin transaction;
                  
                  insert into myTable values1 ...
                  insert into myTable values2 ...;  -- will throw an error
                  
                  commit;
                  

                  现在,在执行时我希望整个事务失败,因此我应该在 myTable 中看到 values1.但不幸的是,即使交易有错误,该表仍使用 values1.

                  now, on execute i want the whole transaction to fail, and therefore i should NOT see values1 in myTable. but unfortunately the table is being pupulated with values1 even though the transaction has errors.

                  有什么想法可以让它回滚吗?(再次,出现任何错误)?

                  any ideas how i make it to roll back? (again, on any error)?

                  EDIT - 从 DDL 更改为标准 SQL

                  EDIT - changed from DDL to standard SQL

                  推荐答案

                  您可以使用 13.6.7.2.DECLARE ... HANDLER 语法如下:

                  DELIMITER $$
                  
                  CREATE PROCEDURE `sp_fail`()
                  BEGIN
                      DECLARE `_rollback` BOOL DEFAULT 0;
                      DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET `_rollback` = 1;
                      START TRANSACTION;
                      INSERT INTO `tablea` (`date`) VALUES (NOW());
                      INSERT INTO `tableb` (`date`) VALUES (NOW());
                      INSERT INTO `tablec` (`date`) VALUES (NOW()); -- FAIL
                      IF `_rollback` THEN
                          ROLLBACK;
                      ELSE
                          COMMIT;
                      END IF;
                  END$$
                  
                  DELIMITER ;
                  

                  有关完整示例,请查看以下 SQL Fiddle.

                  For a complete example, check the following SQL Fiddle.

                  这篇关于mysql 事务 - 回滚任何异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
                  MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
                  Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
                  How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
                  Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
                  Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)

                      1. <small id='62KHX'></small><noframes id='62KHX'>

                        • <bdo id='62KHX'></bdo><ul id='62KHX'></ul>
                          <legend id='62KHX'><style id='62KHX'><dir id='62KHX'><q id='62KHX'></q></dir></style></legend>

                          • <i id='62KHX'><tr id='62KHX'><dt id='62KHX'><q id='62KHX'><span id='62KHX'><b id='62KHX'><form id='62KHX'><ins id='62KHX'></ins><ul id='62KHX'></ul><sub id='62KHX'></sub></form><legend id='62KHX'></legend><bdo id='62KHX'><pre id='62KHX'><center id='62KHX'></center></pre></bdo></b><th id='62KHX'></th></span></q></dt></tr></i><div id='62KHX'><tfoot id='62KHX'></tfoot><dl id='62KHX'><fieldset id='62KHX'></fieldset></dl></div>

                          • <tfoot id='62KHX'></tfoot>
                              <tbody id='62KHX'></tbody>