这个触发器能执行成功 但是无法删除数据
delete from ba2 where a=2
提示错误1442- can't update table "ba2" in stored function/trigger because it is used
by statement which invoked this stored funciton/triggercreate trigger trigger_del_ba2
before delete on ba2 for each row
begin
update ba2 set b=1 where a=(select max(a) from ba2 where a< old.a);
end;
也就是当删除这个表的时候 ,同时update这个表的那个id的上一条记录的 另外一个字段 ,
为什么不能成功 》 (是否mysql触发器删除不能对本表执行)
delete from ba2 where a=2
提示错误1442- can't update table "ba2" in stored function/trigger because it is used
by statement which invoked this stored funciton/triggercreate trigger trigger_del_ba2
before delete on ba2 for each row
begin
update ba2 set b=1 where a=(select max(a) from ba2 where a< old.a);
end;
也就是当删除这个表的时候 ,同时update这个表的那个id的上一条记录的 另外一个字段 ,
为什么不能成功 》 (是否mysql触发器删除不能对本表执行)
begin
update ba2 a, (select max(a) as aa from ba2 where a< id) b set a.b=1 where a.a=b.aa;
delete from ba2 where a=id;end;
LOCK TABLES 是为当前线程锁定表。 UNLOCK TABLES 释放被当前线程持有的任何锁。还有以下几条规则:1. 如果一个线程获得在一个表上的一个READ锁,该线程和所有其他线程只能从表中读。2. 如果一个线程获得一个表上的一个WRITE锁,那么只有持锁的线程READ或WRITE表,其他线程被阻止。3. 当线程发出另外一个LOCK TABLES时,或当服务器的连接被关闭时,
当前线程锁定的所有表会自动被解锁。4. 当前进程无法 访问没有被LOCK 的表 这个不清楚的可以在winows 下开两个命令窗口 (就相当是两个进程了) 然后试试看。CREATE PROCEDURE `ba`(id int)
beginLOCK TABLES -----??不知道如何表达???
update ba2 a, (select max(a) as aa from ba2 where a < id) b set a.b=1 where a.a=b.aa;
delete from ba2 where a=id;UNLOCK TABLES ----??同上
end;