在使用mysql来处理问题时,出现的错误提示:
[SQL] create trigger Category_del
before delete on category
for each ROWIF EXISTS(select* from blog.categoryid=OLD.id)
delete from blog where categoryid=OLD.id[Err] 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 '.id)
delete from blog where categoryid=OLD.id' at line 5业务意思:
当删除category表时,如果blog中的categoryid字段与category中的id字段相同时,如果删除category时,同时删除
blog相应的一行记录!

解决方案 »

  1.   

    你的SELECT语法不对。
    IF EXISTS(select* from blog where categoryid=OLD.id)
    delete from blog where categoryid=OLD.id
      

  2.   

    另外从逻辑上来说,你根本不需要判断是否存在相同的记录。直接删除就行了。create trigger Category_del
    before delete on category
    for each ROW
    delete from blog where categoryid=OLD.id;
      

  3.   

    xiazaicui12 (struts初级)
      '截至2010-11-28 15:03:15  用户结帖率0.00%  当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  4.   

    1:IF语法不全。
    2:FROM后面要跟表名称,不是字段名称。缺少FROMcreate trigger Category_del before delete on category
    for each ROWIF EXISTS(select * from blog where categoryid=OLD.id) then
       delete from blog where categoryid=OLD.id ;
    end if;
      

  5.   

    create trigger Category_del before delete on category
    for each ROWIF EXISTS(select * from blog where categoryid=OLD.id) then
       delete from blog where categoryid=OLD.id ;
    end if;要加THEN