Is it possible to move a record from one table to another using a single SQL statement?

后端 未结 5 1750
我寻月下人不归
我寻月下人不归 2021-01-19 10:41

I need a query to move a record from one table to another without using multiple statements?

5条回答
  •  感动是毒
    2021-01-19 11:32

    Please note that the time delay between insert-select and delete can cause you to delete to much.

    For a safe route you could use an update field:

    update old_table set move_flag=1 where your_criteria
    insert into ... select from ... where move_flag = 1
    delete from old_table where move_flag=1
    

    Or use a transaction which locks the old_table so no data can be added between insert... select and delete.

提交回复
热议问题