表tab3 如果ID大于5,自动改为5,
Create table tab3(id int not null);
Create trigger inser_update_a
Before insert or update on tab3
FOR each ROW 
AS BEGIN 
IF tab3.id >5
then tab3.id= 5
end if
end ;
 上面有错吗, 我运行不出来,报错:
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'or update on tab3
FOR each ROW 
AS BEGIN 
IF tab3.id >5
then tab3.id= 5
end if
e' at line 2
请问各位是怎么回事呢..

解决方案 »

  1.   

    Before insert or update on tab3MySQL不支持这种语法,只能分开写。写两个触发器分别是Create trigger inser_update_a_1 before insert  ....Create trigger inser_update_a_2 before update ....
      

  2.   

    MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  3.   

    ACMAIN_CHM:
     你好,
    我把update 删了,运行:
    Create trigger inser_update_a
    Before insert on tab3
    FOR each ROW 
    AS BEGIN 
    IF tab3.id >5
    then tab3.id= 5
    end if
    end ;
    语法上应该没错,我是看了数据库系统概论里面的一个例子,再用本地的做下实验,但是还是报错:
    Error Code : 1064
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS BEGIN 
    IF tab3.id >5
    then tab3.id= 5
    end if
    end' at line 4
    这是什么问题呢;你说mysql触发器只能用一个触发事件,但是数据库系统概论里面的例子里有2个.为什么也能成功呢.
      

  4.   

    AS BEGIN  MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
    二楼的时候已经贴过一次文档的地址了。为什么不看一下手册中的语法说明和例子?