MySQL为依赖表生成sql插入
我需要创建sql脚本来插入许多表 - 总数接近2000,但表链接(它是一个xml邻接模型) - 所以在插入table1之后,接收id,添加一些数据,插入table2的fk - 先前的id,和数据,重复表 3、表 4 后,... 链接表链的长度 - 超过 20。 问题是:是否存在一些代码生成器,可以从信息模式中读取表之间的关系,并在将某个表作为根之后生成所有插入查询树? 谢谢。
I need create sql script for insert in many tables - total near 2000, but tables linked (it is an xml adjancency model) - so after have inserted in table1, receive id, add some data, insert into fk of table2 - previous id, and data, after repeat for table3, for table 4,...
Length of chain of linked tables - more than 20.
The question is: exists some code generator that can read relations between tables from information schema and - after point some table as root - generate all tree of insert query?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您无法在应用程序层执行此操作,我建议尝试使用 触发器。
本质上,您可以在每个表上创建一个“AFTER INSERT”触发器。就像这样:
然后,对 table1 的插入将触发对 table2 的插入,这将触发对 table3 的插入,依此类推。
If you can't do it on application layer, I suggest trying to do it with Triggers.
Essentially, you would create an "AFTER INSERT" Trigger on each of the tables. Smth like that:
Then, an insert into table1 would trigger an insert into table2, which would trigger an insert into table3 and so on.