插入到多个表中
我正在使用 Delphi2010,我正在尝试插入多个表。我不知道最好的方法来做到这一点。我想知道是否有一种可能的方法可以使用 Delphi 的工具之一(如 TQuery 或 TClientDataSet)进行一次插入,或者使用代码会更好(我们使用 Pascal 语言)。也许是一个数组?我使用 Delphi 的时间不长,但我之前已将信息插入和更新到一张表中,而不是多个表中。此外,这些表使用几乎相同的字段名称。
任何帮助将不胜感激。
提前致谢!!
I am using Delphi2010 and I'm trying to do an insert into multiple tables. I don't know the best way to do this. What I'm wondering is if there is a possible way to do one insert using one of Delphi's tools like the TQuery or TClientDataSet or would it be better to use code (we use Pascal language). An array maybe? I haven't been using Delphi that long but I have inserted and updated info into one table before, not multiple. Also, these tables use pretty much the same field names.
Any help would be greatly appreciated.
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用事务包装器调用存储过程来同时更新表。或者重新设计数据库以消除重复/冗余数据,这样您就不需要一次更新多个表。
请注意,鉴于问题中提供的信息,这个答案是完全有效的......
(注:已经很晚了,睡不着,无聊。考虑到问题中信息的质量,这就是你得到的结果!)
Call a stored procedure to update your tables simultaneously, with a transaction wrapper. Or re-design your database to eliminate duplicate/redundant data, so that you would never need to update several tables at once.
Note that this answer is perfectly valid, given the information provided in the question...
(Note: it's late, couldn't sleep, bored. This is what you get, given the quality of the information in the question!)
另一种可能的解决方案是在数据库上创建一个可更新的视图,并从 Delphi 更新该视图。
制作可更新视图只需将更新 2 个表的工作移至 SQL,而不是在 Delphi 中。
这将业务逻辑移至 sql 而不是 Delphi 中。它可能还会产生更少的网络流量。
正如 Chris 所写:当 2 个或更多更新/插入彼此依赖时,请使用事务。
Another possible solution could be to make a updateable view on the database, and update the view from Delphi.
Making a updateable view just moves the work of updating 2 tables to the SQL instead of in Delphi.
This moves the business logic to the sql instead of in the Delphi. It propobly also generates less network trafic.
As Chris writes: use transactions, when 2 or more updates/inserts is dependent of each other.
您使用哪些数据访问组件?
您有哪些限制?
您想在两个表中插入相同的值吗?
为什么不容易像:
Which data access componentes do you use ?
Which restrictions do you have ?
do you want to insert the same values into both tables ?
why not easy like: