Mysql returning clause equivalent

后端 未结 2 1201
一生所求
一生所求 2020-12-07 01:21

I am a complete newbie to MySql so please be gentle.

Is there an equivalent of the RETURNING clause in Oracle or the Inserted\'/\'Deleted

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 01:30

    Unfortunately, you can't do both insertion and deletion in one query, but you can do it all in one transaction if you are using a transactional store engine (like InnoDB). Moreover, RETURNING is supported by Oracle and PostgreSQL but not by MySQL and therefore you need to write separate delete and insert statements.

    Using a transaction however, will guarantee that only the successfully copied data will be deleted from tableA. Consider the following:

    begin transaction;
    insert into tableB select * from tableA where 'your_condition_here';
    delete from tableA where 'your_condition_here';
    commit;
    

提交回复
热议问题