Move data from one table to another

核能气质少年 提交于 2019-12-11 04:35:19

问题


This question seems to be answered multiple times. However none match the criteria I need.

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?

For example I could do this:

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?


回答1:


No you can't do that.

You should use a transaction if you are worried about the integrity of your tables in between the job.



来源:https://stackoverflow.com/questions/7545512/move-data-from-one-table-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!