检查参照完整性违规删除前 [英] Checking referential integrity rule violation before deletion
本文介绍了检查参照完整性违规删除前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从表中删除行之前,有没有简单的方法来检查,这将违反参照完整性规则?我想从C#赢窗体应用程序做到这一点(.NET 3.5)使用SQL Server 2005。
Before deleting a row from a table, is there any simple way to check that it would violate a referential integrity rule? I'd like to do this from a C# win form application (.Net 3.5) using SQL Server 2005.
推荐答案
有浮现在脑海中的几个潜在选项:
There are a few potential options that come to mind:
- 设置了级联在数据库中删除,以便删除将始终成功
- 检查删除之前,选择与记录。这要求应用程序中有限制的知识。
- 一个好的领域模型(商业类)应允许应用程序需要注意的相关记录。
- 的O / R映射器,如NHibernate的,可以用来定义级联删除操作。
- 使用SMO(Microsoft.SqlServer.Smo)检查为关系数据库架构,然后检查现有的相关记录。我不知道这是可能的。
- Set up cascading deletes in the database so that a delete will always succeed.
- Check for related records with SELECTs before deleting. This requires that the application have knowledge of the constraints.
- A good domain model (business classes) should allow the application to be aware of related records.
- An O/R Mapper, such as NHibernate, can be used to define cascade delete operations.
- Use SMO (Microsoft.SqlServer.Smo) to inspect the database schema for relations, then check for existing related records. I don't know if that's possible.
这篇关于检查参照完整性违规删除前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文