The difference between set autocommit=0 and start transaction in MySQL

Source: Internet
Author: User
Tags rollback savepoint

Set autocommit=0 refers to a transaction that is not automatically committed, since the execution of this sentence, each SQL statement or statement block the transaction needs to display "commit" to commit the transaction.

1, whether autocommit is 1 or 0
After START TRANSACTION, only if the commit data will take effect, the rollback will be rolled back.

2, when autocommit is 0 o'clock
Whether or not there is a start TRANSACTION.
Only if the commit data will take effect will it be rolled back after rollback.

3, if the autocommit is 1, and there is no start TRANSACTION.
It is useless to call rollback. Even if the savepoint is set.

Roll back success

Set autocommit =1;delimiter $ $DROP PROCEDURE IF EXISTS  mmmm $$  CREATE definer= ' tms_admin ' @ '% ' PROCEDURE ' mmmm ' () BEGIN          DECLARE t_error INTEGER DEFAULT 0;    DECLARE CONTINUE HANDLER for sqlexception,sqlwarning,not FOUND  SET t_error=1;        START TRANSACTION;    SavePoint P1;              Update T_user Set instance_seq_id = ' tt00006 ';            Update T_user Set instance_seq_id000 = ' tt00007 ';            IF t_error = 1 then                 ROLLBACK to P1;            ELSE                 COMMIT;             END IF; end$ $DELIMITER; Call ' tms_inst_tt00003 '. ' Mmmm ' ();

Set autocommit =0;delimiter $ $DROP PROCEDURE IF EXISTS  mmmm $$  CREATE definer= ' tms_admin ' @ '% ' PROCEDURE ' mmmm ' () BEGIN          DECLARE t_error INTEGER DEFAULT 0;    DECLARE CONTINUE HANDLER for sqlexception,sqlwarning,not FOUND  SET t_error=1;        START TRANSACTION;    SavePoint P1;              Update T_user Set instance_seq_id = ' tt00006 ';            Update T_user Set instance_seq_id000 = ' tt00007 ';            IF t_error = 1 then                 ROLLBACK to P1;            ELSE                 COMMIT;             END IF; end$ $DELIMITER; Call ' tms_inst_tt00003 '. ' Mmmm ' ();

Roll back success

Set autocommit =0;delimiter $ $DROP PROCEDURE IF EXISTS  mmmm $$  CREATE definer= ' tms_admin ' @ '% ' PROCEDURE ' mmmm ' () BEGIN          DECLARE t_error INTEGER DEFAULT 0;    DECLARE CONTINUE HANDLER for sqlexception,sqlwarning,not FOUND  SET t_error=1;    SavePoint P1;              Update T_user Set instance_seq_id = ' tt00006 ';            Update T_user Set instance_seq_id000 = ' tt00007 ';            IF t_error = 1 then                 ROLLBACK to P1;            ELSE                 COMMIT;             END IF; end$ $DELIMITER;

Roll back success

The difference between set autocommit=0 and start transaction in MySQL

Related Article

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.