snippetsqlMinor
How can I know how many tables my DELETE has changed?
Viewed 0 times
tablescanknowhowdeletehasmanychanged
Problem
Suppose that I have many tables linked by a chain of
(1 row affected)
Is there any way to know how many tables/rows my
ON DELETE CASCADE foreign keys. To the best of my knowledge and experience, deleting from one table gives me no notice at all that I have in fact affected multiple tables. For example, if deleting one row from table1 causes 500 rows to be deleted from table2 then all that SSMS will tell me is(1 row affected)
Is there any way to know how many tables/rows my
DELETE has actually changed? It seems as if, in theory, I could delete one row from one table in a sufficiently evil database and unknowingly delete 99% of the database's data.Solution
If you’re just generally curious, look at the query plan. It will show all the tables involved.
If you’re looking to log or audit them, that’s a different story. You would need to use triggers, or some brand of auditing.
If you’re looking to log or audit them, that’s a different story. You would need to use triggers, or some brand of auditing.
Context
StackExchange Database Administrators Q#335251, answer score: 4
Revisions (0)
No revisions yet.