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
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;
Why not insert the rows to be deleted from table A in table B and then delete the rows from table A? you can achieve that like this:
insert into tableB select * from tableA where condition;
and then
delete from tableA where condition.