2011-08-26 77 views
0

假设我在表A中有一行我希望删除,但在其他表中有多个外键约束。有没有办法自动生成删除命令? 我认为这是一个递归查看外键,然后生成一个删除语句来处理所有外键的工具应该存在,但我找不到一个。有什么办法可以生成级联删除语句吗?

我在MSSQL Server2008的

+3

你都知道了'上删除cascade'选项FKS的? –

+0

http://msdn.microsoft.com/en-us/library/aa933119(v=sql.80).aspx – NullUserException

回答

6

当设置你的外键关系有一个ON DELETE CASCADE,您可以添加。

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. 

所以即使有一个解决方案,你是不是将其添加到表:

In SQL Server 2005, can I do a cascade delete without setting the property on my tables?

相关问题