Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MySQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 这样的触发器怎么建立呀?
mengxiangjava





发贴: 11
积分: 0
于 2008-10-27 10:15 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我有个表t_user此表的id是自动增加的,怎样才能把它的id插入其他两个表t_habit(user_id) ,t_user_info(user_id)用触发器实现,也就是说,但插入t_user表信息时,其它两个表会自动把t_user表的id插入其中,怎么实现?急! 急!急!急!急!急!急!急!急!



作者 Re:这样的触发器怎么建立呀? [Re:mengxiangjava]
mengxiangjava





发贴: 11
积分: 0
于 2008-10-27 10:38 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
CREATE DEFINER='95try'@`%` TRIGGER `user_info_trigger` AFTER INSERT ON `t_user`
FOR EACH ROW insert into t_user_info (user_id)
select b.id from t_user b
where b.id = LAST_INSERT_ID();




作者 Re:这样的触发器怎么建立呀? [Re:mengxiangjava]
mengxiangjava





发贴: 11
积分: 0
于 2008-10-27 11:14 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
DROP TRIGGER IF EXISTS `user_info_trigger`;
CREATE DEFINER='95try'@`%` TRIGGER `user_info_trigger` AFTER INSERT ON `t_user`
FOR EACH ROW begin
insert into t_user_info (user_id)
select b.id from t_user b
where b.id = LAST_INSERT_ID();

insert into t_habit (user_id)
select b.id from t_user b
where b.id = LAST_INSERT_ID();

insert into t_corp (user_id)
select b.id from t_user b
where b.id = LAST_INSERT_ID();

end;





flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923