13

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?

Sam
  • 7,252
  • 16
  • 46
  • 65
kjv
  • 11,047
  • 34
  • 101
  • 140

3 Answers3

15

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.

tzot
  • 92,761
  • 29
  • 141
  • 204
5

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

hollystyles
  • 4,979
  • 2
  • 36
  • 38
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.

AJ.
  • 13,461
  • 19
  • 51
  • 63
  • Actually, it's not Joel Coehoorn that points that out. If unsure of the author, you better use "that answer" linking to its permalink. – tzot Oct 03 '08 at 11:45