一个mysql触发器需求,

netfound 2007-04-16 06:14:25
库1种表A存有一系列的 数据库名称(这些数据库里面表结构完全一致),现在我要在一张表B上建立一个触发器,触发器内容是循环表A中的库,依次向这些库中的一个表X执行插入数据的操作。指点一下怎么操作?
...全文
433 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
netfound 2007-04-17
  • 打赏
  • 举报
回复
create trigger ins_b_insert before insert on users
for each row
begin
declare stopFlag int;
declare dbname varchar(20) default '';
declare stcur cursor for select sitename from test.site;
declare continue handler for not found set stopFlag =1;
open stcur;
repeat
fetch stcur into dbname;
/*看下面的语句,应该知道意思了吧,DBname就是数据库的名称,这个我不知道证明方到sql中去*/
insert into dbname.users(username,password) select username,password from users where id=new.id;
until stopFlag =1
end repeat;
close stcur;
end;
netfound 2007-04-17
  • 打赏
  • 举报
回复
在insert的时候触发。然后向表A中记录的所有库中每个库里面的表X插入数据。
ChumpKlutz 2007-04-17
  • 打赏
  • 举报
回复
描述的不明确,看起来像是存储过程的需求

请问在B表的什么操作下触发该触发器,Update?Delete?Insert?..

57,062

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧