插入删除查询后无法触发

时间:2016-06-01 14:46:07

标签: mysql mysqli triggers database-trigger

我在插入后写入触发器工作并检查计数记录是否超过500,删除一条记录但不能正常工作 此处代码

CREATE TRIGGER `delrecord` after insert on `tbl_coins`
FOR EACH ROW
BEGIN
DECLARE recordcount INT;
DECLARE deleterecordcount INT;

set recordcount = (select count(*) from tbl_coins);

if recordcount > 500

then
set deleterecordcount = (select ID from tbl_coins order by time asc   limit 1);

delete from tbl_coins 

where ID = deleterecordcount;

end if;
END

非常感谢

0 个答案:

没有答案