[SQL] CREATE TRIGGER 'ASDF' BEFORE INSERT ON 'users'
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,发现有些地方有差异,请求帮忙.
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,发现有些地方有差异,请求帮忙.
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>//
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;
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我改成了另外的表插入,还是不行,你帮看一下.
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>
insert into test (name,tel) values('test',13100000000);
end;
BGEIN建议你参考一下MYSQL的手册。MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html