SQL Server:删除具有外键约束的行:事务可以覆盖约束吗? [英] SQL Server: Deleting Rows with Foreign Key Constraints: Can Transactions override the constraints?

查看:330
本文介绍了SQL Server:删除具有外键约束的行:事务可以覆盖约束吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个表,其中添加了外键约束。这些用于代码生成,以在生成的存储过程中设置特定的联接。

I have a few tables where Foreign Key constraints are added. These are used with code generation to set up specific joins in generated stored procedures.

可以通过在事务中调用多个删除来覆盖这些约束,特别是TransactionScope在C#或是级联删除绝对需要?

Is it possible to override these constraints by calling multiple deletes within a transaction, specifically "TransactionScope" in C# or is cascaded deleting absolutely required?

推荐答案

不要使用级联删除,可以导致严重的性能问题。最好的过程是按照从最低子表到父表的顺序执行删除。

Do not use cascade delete, you can cause serious performance issues that way. The best procedure is to do the deletes in order from the lowest child table up to the parent table.

禁用外键是出现数据完整性问题的处方。唯一需要做的事情是DBA,他是非常有经验的,很好地意识到可能导致的问题。如果你问这个问题,你还没有足够的经验来使用这种技术。记住当你禁用FK,你禁用所有人,而不只是你的进程。

Disabling the foreign keys is a prescription for having data integrity problems. The only time something like that should be done is by a DBA who is extremely experienced and well aware of the issues that could cause. If you are asking this question, you are not yet experienced enough to use that technique. Remember when you disable the FK, you disable it for everyone not just your process.

这篇关于SQL Server:删除具有外键约束的行:事务可以覆盖约束吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆