简体   繁体   中英

Does CASCADE Delete execute as transaction?

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?

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM