FOR EACH ROW
BEGIN
INSERT INTO USERS (AGE) VALUES(30);
END;
[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 ''ASDF' BEFORE INSERT ON 'users'
FOR EACH ROW
BEGIN
INSERT INTO USERS (AGE) ' at line 1
兄弟们,我以前用SQL,现在改用MYSQL,发现有些地方有差异,请求帮忙.
10 个解决方案
#1
是在MYSQL命令行下输入?
mysql>delimiter //
mysql>CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
mysql>FOR EACH ROW
mysql>BEGIN
mysql>INSERT INTO USERS (AGE) VALUES(30);
mysql>END;
mysql>//
mysql>delimiter //
mysql>CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
mysql>FOR EACH ROW
mysql>BEGIN
mysql>INSERT INTO USERS (AGE) VALUES(30);
mysql>END;
mysql>//
#2
是在navicat 8 for mysql 中文版sql编辑器中访问
#3
1. 语法上的问题。 改成
2. 方法上的问题。 MYSQL中触发器中不能操作当前表,也就是users表的触发器中不能再 insert into users ...
改成
CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
FOR EACH ROW
INSERT INTO USERS (AGE) VALUES(30);
2. 方法上的问题。 MYSQL中触发器中不能操作当前表,也就是users表的触发器中不能再 insert into users ...
改成
CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
FOR EACH ROW
set new.AGE=30;
#4
我在mysql 命令行下输入你给的那句,还是报同样的错
#5
[SQL] CREATE TRIGGER `asdf` BEFORE INSERT ON `users` FOR EACH ROW BGEIN
insert into test (name,tel) values('test',13100000000);
[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 'insert into test (name,tel) values('test',13100000000)' at line 2
我改成了另外的表插入,还是不行,你帮看一下.
insert into test (name,tel) values('test',13100000000);
[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 'insert into test (name,tel) values('test',13100000000)' at line 2
我改成了另外的表插入,还是不行,你帮看一下.
#6
mysql> create table users (uid int, age int);
Query OK, 0 rows affected (0.09 sec)
mysql> create table test (name varchar(10), tel varchar(20));
Query OK, 0 rows affected (0.06 sec)
mysql> CREATE TRIGGER `asdf` BEFORE INSERT ON `users`
-> FOR EACH ROW
-> insert into test (name,tel) values('test',13100000000);
Query OK, 0 rows affected (0.11 sec)
mysql> insert into users values(1,20);
Query OK, 1 row affected (0.08 sec)
mysql> select * from users;
+------+------+
| uid | age |
+------+------+
| 1 | 20 |
+------+------+
1 row in set (0.00 sec)
mysql> select * from test;
+------+-------------+
| name | tel |
+------+-------------+
| test | 13100000000 |
+------+-------------+
1 row in set (0.00 sec)
mysql>
#7
REATE TRIGGER `asdf` BEFORE INSERT ON `users` FOR EACH ROW BEgIN
insert into test (name,tel) values('test',13100000000);
end;
insert into test (name,tel) values('test',13100000000);
end;
#8
你多了个 begin
CREATE TRIGGER `asdf` BEFORE INSERT ON `users` FOR EACH ROWBGEIN
CREATE TRIGGER `asdf` BEFORE INSERT ON `users` FOR EACH ROW
#9
MySQL 语法和 SQL server 基本类似,但略有差别。
建议你参考一下MYSQL的手册。
MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
建议你参考一下MYSQL的手册。
MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
#10
好的,谢谢
#1
是在MYSQL命令行下输入?
mysql>delimiter //
mysql>CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
mysql>FOR EACH ROW
mysql>BEGIN
mysql>INSERT INTO USERS (AGE) VALUES(30);
mysql>END;
mysql>//
mysql>delimiter //
mysql>CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
mysql>FOR EACH ROW
mysql>BEGIN
mysql>INSERT INTO USERS (AGE) VALUES(30);
mysql>END;
mysql>//
#2
是在navicat 8 for mysql 中文版sql编辑器中访问
#3
1. 语法上的问题。 改成
2. 方法上的问题。 MYSQL中触发器中不能操作当前表,也就是users表的触发器中不能再 insert into users ...
改成
CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
FOR EACH ROW
INSERT INTO USERS (AGE) VALUES(30);
2. 方法上的问题。 MYSQL中触发器中不能操作当前表,也就是users表的触发器中不能再 insert into users ...
改成
CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
FOR EACH ROW
set new.AGE=30;
#4
我在mysql 命令行下输入你给的那句,还是报同样的错
#5
[SQL] CREATE TRIGGER `asdf` BEFORE INSERT ON `users` FOR EACH ROW BGEIN
insert into test (name,tel) values('test',13100000000);
[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 'insert into test (name,tel) values('test',13100000000)' at line 2
我改成了另外的表插入,还是不行,你帮看一下.
insert into test (name,tel) values('test',13100000000);
[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 'insert into test (name,tel) values('test',13100000000)' at line 2
我改成了另外的表插入,还是不行,你帮看一下.
#6
mysql> create table users (uid int, age int);
Query OK, 0 rows affected (0.09 sec)
mysql> create table test (name varchar(10), tel varchar(20));
Query OK, 0 rows affected (0.06 sec)
mysql> CREATE TRIGGER `asdf` BEFORE INSERT ON `users`
-> FOR EACH ROW
-> insert into test (name,tel) values('test',13100000000);
Query OK, 0 rows affected (0.11 sec)
mysql> insert into users values(1,20);
Query OK, 1 row affected (0.08 sec)
mysql> select * from users;
+------+------+
| uid | age |
+------+------+
| 1 | 20 |
+------+------+
1 row in set (0.00 sec)
mysql> select * from test;
+------+-------------+
| name | tel |
+------+-------------+
| test | 13100000000 |
+------+-------------+
1 row in set (0.00 sec)
mysql>
#7
REATE TRIGGER `asdf` BEFORE INSERT ON `users` FOR EACH ROW BEgIN
insert into test (name,tel) values('test',13100000000);
end;
insert into test (name,tel) values('test',13100000000);
end;
#8
你多了个 begin
CREATE TRIGGER `asdf` BEFORE INSERT ON `users` FOR EACH ROWBGEIN
CREATE TRIGGER `asdf` BEFORE INSERT ON `users` FOR EACH ROW
#9
MySQL 语法和 SQL server 基本类似,但略有差别。
建议你参考一下MYSQL的手册。
MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
建议你参考一下MYSQL的手册。
MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
#10
好的,谢谢