0

is it possible to find out the amount of rows that will be deleted in each table when one row is deleted in a table?

For example, I have a row in a product table. I deleted a product and since i have use on delete cascade, the other rows in different tables such as Comments and Price will be deleted. Is it possible to get the amount of rows that will be deleted from the other tables as a string?

The sample output will be "3 rows of comment will be deleted\n 1 rows of price will be deleted" Thanks in advance!

Wolfeatspotatoes
  • 115
  • 1
  • 2
  • 10
  • 1
    How about just getting the count of comments and prices under that product? – bolkay Jun 11 '19 at 11:01
  • 1
    `_db.Comments.Count(c => c.ProductId == pId)` and `_db.Prices.Count(p => p.ProductId == pId)` for example? Or even `myProduct.Comments.Count` and `myProduct.Prices.Count` if you have navigation properties – Rafalon Jun 11 '19 at 11:03
  • 2
    Only by: counting all the rows you intend to delete.. OR.. counting the rows before, running the delete in a transaction, counting the rows after and then rolling back.. But even then, in a busy DB you should note that the message might be out of data as soon as you present it – Caius Jard Jun 11 '19 at 11:05
  • Ohh yeah that makes a lot of sense, thanks all of you guys! – Wolfeatspotatoes Jun 11 '19 at 12:18

1 Answers1

1

Check Out This Answer, This may help you to Solve your Problem.

Oracle Delete Statement: how many rows have been deleted by cascade delete

Aditya Dhanraj
  • 189
  • 1
  • 1
  • 12
  • 1
    Note that this handles *have been* when OP wants to know *will be*. Also please note that link-(almost)only answers are considered as poor answers as links can become obsolete. – Rafalon Jun 11 '19 at 11:40