测试表:
create table to_send ( 
channel int,
other1 int,
other2 int
) create table chanelChangeTest ( 
oldChanel varchar(20),
newChanel varchar(20),
OperTimer varchar(20)  

我现在是这样写的:
create trigger whenToSendChange 
after update 
on to_send 
for each row 
begin
insert into chanelChangeTest
values(old.channel,new.channel,now()); 
end; 
执行是如果to_send有UPDATE就插入。
我想要的是:只有当to_send的channel列被UPDATE时才INSERT,其他列UPDATE不作INSERT动作,
应该怎么改这个trigger。

解决方案 »

  1.   

    create trigger whenToSendChange
    after update
    on to_send
    for each row
    begin
    if old.channel<>new.channel then
    insert into chanelChangeTest
    values(old.channel,new.channel,now());
    end if;
    end; 
      

  2.   

    版本是:Server version: 5.0.45-community MySQL Community Edition (GPL)
    SQL 执行错误#1064.从数据库响应:
    You have an error in your SQL syntax:check the manual that correponds to your MySQL server version for the right syntax to user near '' at line 9.
      

  3.   

    DELIMITER $$CREATE trigger whenToSendChange after update on to_send 
        FOR EACH ROW 
    begin
    if old.channel <>new.channel then
    insert into chanelChangeTest
    values(old.channel,new.channel,now());
    end if;    END$$DELIMITER ;
      

  4.   

    我直接在MYSQL FRONT里执行,怎么还是一样的错误呢?
    You have an error in your SQL syntax:check the manual that correponds to your MySQL server version for the right syntax to user near '' at line 8. 
      

  5.   

    以在SQLYOG中测试了一下,确实没有问题