不幸的是,您不能在 一个查询中 同时进行插入和删除 操作 ,但是如果您使用的是事务存储引擎(例如InnoDB),则可以在一个 事务中
完成所有操作。此外,
RETURNING它受Oracle和PostgreSQL支持,但不受MySQL支持,因此您需要编写单独的
delete和
insert语句。
但是,使用事务将确保仅成功复制的数据将从tableA中删除。考虑以下:
begin transaction;insert into tableB select * from tableA where 'your_condition_here';delete from tableA where 'your_condition_here';commit;



