CASCADE Delete是否作为事务执行?

时间:2022-09-19 03:41:32

I want to perform cascade delete for some tables in my database, but I'm interested in what happens in case there's a failure when deleting something. Will everything rollback?

我想对我的数据库中的某些表执行级联删除,但我对在删除某些内容时出现故障时会发生什么感兴趣。一切都会回滚吗?

3 个解决方案

#1


14  

In general¹, yes, cascade deletes are done in the same transaction (or subtransaction) as your original delete. You should read the documentation of your SQL server, though.

通常¹,是的,级联删除是在与原始删除相同的事务(或子事务)中完成的。但是,您应该阅读SQL服务器的文档。

¹ The exception is if you're using a database that doesn't support transactions, like MySQL with MyISAM tables.

¹例外情况是,如果您使用的数据库不支持事务,例如MySQL和MyISAM表。

#2


2  

Cascade deletes are indeed atomic, they would be of little use without that property. It is in the documentation.

级联删除确实是原子的,如果没有该属性,它们将毫无用处。它在文档中。

#3


1  

It's worth pointing out that any cascading event should be atomic (i.e. with in a transaction). But, as Joel Coehoorn points out, check the documentation for your database.

值得指出的是,任何级联事件都应该是原子的(即在事务中)。但是,正如Joel Coehoorn指出的那样,检查数据库的文档。

#1


14  

In general¹, yes, cascade deletes are done in the same transaction (or subtransaction) as your original delete. You should read the documentation of your SQL server, though.

通常¹,是的,级联删除是在与原始删除相同的事务(或子事务)中完成的。但是,您应该阅读SQL服务器的文档。

¹ The exception is if you're using a database that doesn't support transactions, like MySQL with MyISAM tables.

¹例外情况是,如果您使用的数据库不支持事务,例如MySQL和MyISAM表。

#2


2  

Cascade deletes are indeed atomic, they would be of little use without that property. It is in the documentation.

级联删除确实是原子的,如果没有该属性,它们将毫无用处。它在文档中。

#3


1  

It's worth pointing out that any cascading event should be atomic (i.e. with in a transaction). But, as Joel Coehoorn points out, check the documentation for your database.

值得指出的是,任何级联事件都应该是原子的(即在事务中)。但是,正如Joel Coehoorn指出的那样,检查数据库的文档。