简体   繁体   English

创建触发器时出现错误1064

[英]Error 1064 when creating Trigger

I am using MYSQL 5.6 and phpMyAdmin 4.1.14 我正在使用MYSQL 5.6和phpMyAdmin 4.1.14

I am trying to create a Trigger that will copy data from one db to another but get the following error: 我正在尝试创建一个触发器,该触发器将数据从一个数据库复制到另一个数据库,但出现以下错误:

#1064 - You have an error in your SQL syntax; #1064-您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'new.airplane_id,new.user_id,new.icao24,new.created_at,new.timestamp,new.altitude' at line 7 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第7行的“ new.airplane_id,new.user_id,new.icao24,new.created_at,new.timestamp,new.altitude”附近使用

Any pointers would be gratefully received 任何指针将不胜感激

My code is: 我的代码是:

CREATE TRIGGER airfields_insert 
BEFORE INSERT 
ON realtime 
FOR EACH ROW
BEGIN
if (new.squawk between 6160 and 6167 or new.squawk between 6171 and 6177) and new.altitude <= 4000 then 
insert into airfields (airplane_id,user_id,icao24,created_at,timestamp,altitude,flight_number,latitude,longitude,heading,squawk,horizontal_speed,vertical_speed,Interested) (new.airplane_id,new.user_id,new.icao24,new.created_at,new.timestamp,new.altitude,new.flight_number,new.latitude,new.longitude,new.heading,new.squawk,new.horizontal_speed,new.vertical_speed,new.Interested);
end if;

You have Syntax error in insert query Your QUERY should be like that 您在插入查询中遇到语法错误您的QUERY应该像这样

insert into airfields (airplane_id,user_id,icao24,.......) 
values (new.airplane_id,new.user_id,new.icao24,........);

or simply 或简单地

 insert into airfields values (new.airplane_id,new.user_id,new.icao24,........);

The form does not specify the column names where the data will be inserted, only their values: 该表格没有指定要在其中插入数据的列名,仅指定了它们的值:

You are missing the VALUES keyword in your INSERT statement 您在INSERT语句中缺少VALUES关键字

Your current INSERT query 您当前的INSERT查询

insert into airfields (airplane_id,user_id,icao24,.......) 
(new.airplane_id,new.user_id,new.icao24,........);
end if;

It should be 它应该是

insert into airfields (airplane_id,user_id,icao24,.......) 
values (new.airplane_id,new.user_id,new.icao24,........);
end if;

Also, you are missing the END keyword after END IF 另外,您在END IF后缺少END关键字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM