问题描述
我是MySql的完全新手,所以请保持谦虚.
I am a complete newbie to MySql so please be gentle.
在Oracle中,是否等效于Oracle中的RETURNING
子句,或者在MySQL中是否等效于SQL Server中的Inserted'/'Deleted
表?我要执行的操作如下:
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:
- 从表A删除一组行
-
将已删除的行集插入表B.
- Delete a set of rows from table A
Insert the deleted set of rows into table B.
请帮助!
谢谢
推荐答案
不幸的是,您不能在一个查询中同时进行插入和删除,但是您可以一次完成所有操作交易(如果您使用的是交易存储引擎(例如InnoDB)).此外,Oracle和PostgreSQL支持RETURNING
,而MySQL不支持RETURNING
,因此您需要编写单独的delete
和insert
语句.
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.
但是,使用事务将确保仅成功复制的数据将从tableA中删除.请考虑以下内容:
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;
这篇关于MySQL返回子句等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!