zoukankan      html  css  js  c++  java
  • MariaDB TRANSACTION

    MariaDB TRANSACTION


    • Transaction—A block of SQL statements

    • Rollback—The process of undoing specified SQL statements

    • Commit—Writing unsaved SQL statements to the database tables

    • Savepoint—A temporary placeholder in a transaction set to which you can issue a rollback (as opposed to rolling back an entire transaction) 


    始终以START TRANSACTION为新起点遇到最后的ROLLBACK savepoint或COMMIT时自动关闭

    ROLLBACK

    (jlive)[crashcourse]>SELECT * FROM ordertotals; START TRANSACTION;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20005 |  158.86 |

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    |     20008 |  132.50 |

    |     20009 |   40.78 |

    |     20009 |   40.78 |

    +-----------+---------+

    6 rows in set (0.00 sec)

    (jlive)[crashcourse]>START TRANSACTION;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>DELETE FROM ordertotals;

    Query OK, 6 rows affected (0.00 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    Empty set (0.00 sec)


    (jlive)[crashcourse]>ROLLBACK;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20005 |  158.86 |

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    |     20008 |  132.50 |

    |     20009 |   40.78 |

    |     20009 |   40.78 |

    +-----------+---------+

    6 rows in set (0.00 sec)



    COMMIT

    START TRANSACTION;
    DELETE FROM orderitems WHERE order_num = 20010; 

    DELETE FROM orders WHERE order_num = 20010; 

    COMMIT; 


    SAVEPOINT

    (jlive)[crashcourse]>START TRANSACTION;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20005 |  158.86 |

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    |     20008 |  132.50 |

    |     20009 |   40.78 |

    |     20009 |   40.78 |

    +-----------+---------+

    6 rows in set (0.00 sec)


    (jlive)[crashcourse]>SAVEPOINT delete1;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>DELETE FROM ordertotals WHERE order_num = 20009;

    Query OK, 2 rows affected (0.00 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20005 |  158.86 |

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    |     20008 |  132.50 |

    +-----------+---------+

    4 rows in set (0.01 sec)


    (jlive)[crashcourse]>SAVEPOINT delete2;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>DELETE FROM ordertotals WHERE order_num = 20005;

    Query OK, 1 row affected (0.01 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    |     20008 |  132.50 |

    +-----------+---------+

    3 rows in set (0.00 sec)


    (jlive)[crashcourse]>SAVEPOINT delete3;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>DELETE FROM ordertotals WHERE order_num = 20008;

    Query OK, 1 row affected (0.00 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    +-----------+---------+

    2 rows in set (0.00 sec)


    (jlive)[crashcourse]>ROLLBACK TO delete3;

    Query OK, 0 rows affected (0.01 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    |     20008 |  132.50 |

    +-----------+---------+

    3 rows in set (0.00 sec)


    (jlive)[crashcourse]>ROLLBACK TO delete2;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20005 |  158.86 |

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    |     20008 |  132.50 |

    +-----------+---------+

    4 rows in set (0.00 sec)


    (jlive)[crashcourse]>ROLLBACK TO delete1;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>SELECT * FROM ordertotals;

    +-----------+---------+

    | order_num | total   |

    +-----------+---------+

    |     20005 |  158.86 |

    |     20006 |   58.30 |

    |     20007 | 1060.00 |

    |     20008 |  132.50 |

    |     20009 |   40.78 |

    |     20009 |   40.78 |

    +-----------+---------+

     

    6 rows in set (0.00 sec)



    修改默认的COMMIT方式


    (jlive)[crashcourse]>SHOW VARIABLES LIKE 'autocommit';

    +---------------+-------+

    | Variable_name | Value |

    +---------------+-------+

    | autocommit    | ON    |

    +---------------+-------+

    1 row in set (0.00 sec)


    (jlive)[crashcourse]>SET autocommit = 0;

    Query OK, 0 rows affected (0.00 sec)


    (jlive)[crashcourse]>SHOW VARIABLES LIKE 'autocommit';

    +---------------+-------+

    | Variable_name | Value |

    +---------------+-------+

    | autocommit    | OFF   |

    +---------------+-------+

     

    1 row in set (0.00 sec)

    • 相关阅读:
      基于OpenVINO的端到端DL网络-GOMfcTemplate在vs2017上的运行并融合Dnn模块
      Windows环境下最新OpenCV和Contribute代码的联合编译【20190505更新红字】
      图像处理程序的序列化和反序列化
      OpenCv dnn模块扩展研究(1)--style transfer
      OpenCV自带dnn的Example研究(5)— segmentation
      OpenCV自带dnn的Example研究(6)— text_detection
      OpenCV自带dnn的Example研究(3)— object_detection
      OpenCV自带dnn的Example研究(4)— openpose
      OpenCV自带dnn的Example研究(1)— classification
      OpenCV自带dnn的Example研究(2)— colorization
    • 原文地址:https://www.cnblogs.com/lixuebin/p/10814164.html
    Copyright © 2011-2022 走看看