Is there any way to generate a cascade delete statement?
Let's say I have a row in Table A I wish to delete but there a multiple foreign key constraints in other tables. Is there a way to automatically generate the delete command? I think a tool that would recursively look at the foreign keys and in turn generate a delete statement to take care of all for开发者_Python百科eign keys should exist, but I can't find one.
I'm on MSSql server2008
When setting up your Foreign Key relationships there is an ON DELETE CASCADE
you can add.
MSDN Cascading Referential Integrity Constraints
ON DELETE CASCADE
Specifies that if an attempt is made to delete a row with a key referenced by foreign
keys in existing rows in other tables, all rows containing those foreign keys are also
deleted. If cascading referential actions have also been defined on the target tables,
the specified cascading actions are also taken for the rows deleted from those tables.
SO even has a solution where you are not adding it to the table:
In SQL Server 2005, can I do a cascade delete without setting the property on my tables?
精彩评论