表一:
id textid title desc address
1 2 国家 中国 复兴路1号表二:
id textid title address
3 2 国家 复兴路1号
当表一textid有数据时,就同时触发表二相关字段
id textid title desc address
1 2 国家 中国 复兴路1号表二:
id textid title address
3 2 国家 复兴路1号
当表一textid有数据时,就同时触发表二相关字段
解决方案 »
- mysql sql查询
- 用MYSQL BACKUP工具备份出来的SQL,如何还原?
- datetimepicker显示问题
- you have an error in your sql syntax;check the manual
- mysql partition 后出现的问题!
- 关于mysql中文显示为"?"的几个问题!在线等等~
- 求解一条优化的select
- 如果在mysql的一个数据库中添加数万个甚至是几百万个表效率和稳定性如何?
- mysql分割查询的求助
- 创建外键并保存后,外键不出现,反而出现一个索引。。。。尝试了多种代码,其他电脑运行都正常,求解。
- mysql 触发器怎么写 v:5.0.6
- mysql的高级管理对于编程的地位如何?
表一:
id textid title desc address
1 2 国家 中国 复兴路1号
2 33 国家2 日本 东京表二:
id textid title address
3 2 国家 复兴路1号
4 33 国家2 东京
insert into b2(textid,title,desc,address)
values (new.textid,new.title,new.desc,new.address)
FOR EACH ROW BEGIN
INSERT INTO table2(textid,title,address) VALUES (NEW.textid,NEW.title,NEW.address);
END;
|DELIMITER ;
首先谢谢,但我刚试了一下运行提示:1458 incorrect routine name
这是要当插入b1是同时插入b2,不是只插入b2b1
id textid title desc address
1 2 国家 中国 复兴路1号
2 33 国家2 日本 东京 b2:
id textid title address
3 2 国家 复兴路1号
4 33 国家2 东京
触发器这样写?报错啊,是不是mysql5.0不支持解发器啊?
CREATE TRIGGER testref BEFORE INSERT ON table1
FOR EACH ROW BEGIN
INSERT INTO table2(textid,title,address) VALUES (NEW.textid,NEW.title,NEW.address);
END;
1 2 国家 中国 复兴路1号
2 33 国家2 日本 东京 表二:
id ttid title address
3 2 国家 复兴路1号
4 33 国家2 东京 刚才有错误描述,textid 对应 ttid 其它不变
楼上,你表名改了吗? 贴出你的SQL语句和整个报错信息。
id textid title desc address
1 2 国家 中国 复兴路1号
2 33 国家2 日本 东京 表二:
id ttid title address
3 2 国家 复兴路1号
4 33 国家2 东京 textid 对应 ttid
FOR EACH ROW BEGIN
INSERT INTO table2(ttid ,title,address) VALUES (NEW.textid,NEW.title,NEW.address);
END;
|DELIMITER ;贴出你自己的SQL及错误信息。
SQL 查询: DELIMITER;MySQL 返回: #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 'DELIMITER' at line 1
SQL 查询: CREATE TRIGGER testref BEFORE INSERT ON t1
FOR EACH
ROW BEGIN
INSERT INTO t2( ttid, title, address )
VALUES (NEW.textid, NEW.title, NEW.address
);MySQL 返回: #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 '' at line 3
DELIMITER $$DROP TRIGGER /*!50032 IF EXISTS */ `zz`.`ff`$$CREATE
TRIGGER `ff` AFTER INSERT ON `aa`
FOR EACH ROW BEGIN
begin
INSERT INTO table2(ttid,title,address) VALUES (NEW.textid,NEW.title,NEW.address);
end;
END;
$$DELIMITER ;