English 中文(简体)
• 如何回落Mysql?
原标题:How to roll back in Mysql?

我打算执行多次指挥,以更新客户数据库,但我希望该指挥部在一次交易中执行,如果在一次指挥中发生错误,所有变动都将得到支持。

当我以这个例子来管理该守则时,如果存在试验2表,则退缩没有奏效,插入的行文存在于测试表中。

What am I doing wrong?

MySQL server is 5.1. the engine of tables is Innodb.

守则实例:

set autocommit = 0;
drop procedure if EXISTS rollbacktest;
delimiter //

CREATE PROCEDURE rollbacktest ()
   BEGIN

   DECLARE CONTINUE HANDLER FOR SQLEXCEPTION,SQLWARNING  SET @x2 = 4; 
   SET autocommit = 0;
   start transaction;   

    SET @x2 = 0;

insert into test(t)values (800);

CREATE TABLE `test2` (
`t`  int(11) UNSIGNED NOT NULL 
    )
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_persian_ci ;


if @x2 = 4 THEN    ROLLBACK; else  commit;    end if;

   END;
//

CALL rollbacktest()
问题回答

您的问题是,你重新做“DDL”(CREATE TABLE)在交易中不能做,因此暗含着你以前所做的 st。

如果你tro到<代码>,情况也将如此。 DROP TABLE,ALTER TABLE, or UNCATE TABLE/code>, 除其他外。 基本上,任何无法收回的报表都会导致现有交易成为自动<代码>。 COMMIT

如果我正确记住,<代码>CREATE TABLE就暗中进行交易。

rel=“nofollow”http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签