将数据从一个表移动到另一个表 [英] Move data from one table to another
问题描述
该问题似乎已被回答多次.但是,没有一个符合我需要的标准.
This question seems to be answered multiple times. However none match the criteria I need.
是否可以选择(并将它们插入到另一个表中)并从Mysql的原始表中删除行,而无需两次运行所选条件?
Is it possible to select (and insert them in another table) and delete rows from the original table in Mysql without running the selected criteria twice?
例如,我可以这样做:
INSERT INTO main (SELECT * FROM temp WHERE age > 30)
DELETE FROM cache WHERE age > 30
但是对于一个非常复杂且运行时间较长的查询,该查询的匹配部分"将执行两次,而我认为应该有一种删除所选项目的解决方案,因为无论如何您都已经获取了它们.
However with a very complex and long running query the 'match part' of the query would be executed twice, whilst I think that there should be a solution to delete the selected items, since you have fetched them already anyways.
我的问题是可能的,如果可以的话.怎么样?
My question, is this possible, and if so. How?
推荐答案
不,您不能这样做.
如果您担心作业之间的表完整性,则应该使用事务.
You should use a transaction if you are worried about the integrity of your tables in between the job.
这篇关于将数据从一个表移动到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!