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 tables in SQL Server in MySQL? What I want to do is the following:
- Delete a set of rows from table A
-
Insert the deleted set of rows into table B.
Please help!
Thanks
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,
RETURNINGis supported by Oracle and PostgreSQL but not by MySQL and therefore you need to write separatedeleteandinsertstatements.Using a transaction however, will guarantee that only the successfully copied data will be deleted from tableA. Consider the following: