测试表:
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。
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。
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;
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.
FOR EACH ROW
begin
if old.channel <>new.channel then
insert into chanelChangeTest
values(old.channel,new.channel,now());
end if; END$$DELIMITER ;
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.