今天遇到一个很奇怪的问题,是关于创建触发器的。创建触发器代码如下create trigger trigger_t_test_U
after update
on t_test
for each row
begin
insert into t_syn_data(table_name,event_type,pk_data,create_time,from_source)
values('t_test','U',NEW.id,now(),'127.0.0.1_mysql_server');
set @key=LAST_INSERT_ID();
insert into t_syn_value(syndata_id,filed_name,filed_value,filed_struct,filed_file,filed_type)
values(@key,'name',NEW.name,'0','-1','1');
end;在MYSQL中对表t_test创建触发器时,提示第7行有错“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 '' at line 7”。
可是我找了半天都没看明白,到底是哪里错了呢?
after update
on t_test
for each row
begin
insert into t_syn_data(table_name,event_type,pk_data,create_time,from_source)
values('t_test','U',NEW.id,now(),'127.0.0.1_mysql_server');
set @key=LAST_INSERT_ID();
insert into t_syn_value(syndata_id,filed_name,filed_value,filed_struct,filed_file,filed_type)
values(@key,'name',NEW.name,'0','-1','1');
end;在MYSQL中对表t_test创建触发器时,提示第7行有错“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 '' at line 7”。
可是我找了半天都没看明白,到底是哪里错了呢?
select LAST_INSERT_ID() into @key;
create trigger trigger_t_test_U
after update
on t_test
for each row
begin
insert into t_syn_data(table_name,event_type,pk_data,create_time,from_source)
values('t_test','U',NEW.id,now(),'127.0.0.1_mysql_server');
select LAST_INSERT_ID() into @key;
insert into t_syn_value(syndata_id,filed_name,filed_value,filed_struct,filed_file,filed_type)
values(@key,'name',NEW.name,'0','-1','1');
end;
delimiter;
加上之后,报错哦:
You tried to execute any empty string.Please type an SQL command into the SQL edit field and execute again.
依然不行哦,还是报:
You tried to execute any empty string.Please type an SQL command into the SQL edit field and execute again.另外,我是在一个MYSQL的工具里执行的,并不是在命令行执行的哦。
回复9楼朋友,那工具是叫一种“mysql-gui-tools”。另外,我用程序进行JDBC连接来创建触发器时,也是报“语法有错”。
用命令行模式倒是可以创建成功,但是还有问题,以下为命令行窗口提示:
Query OK,0 rows affected (0.00sec)Error 1064(42000):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 'delimiter' at line 1mysql>