防止从数据库中删除记录 [英] Preventing record deletion from the database

查看:111
本文介绍了防止从数据库中删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果该项目在其他地方使用我们怎样才能从数据库中删除项目我们如何在项目中使用
来帮助

how we can not delete item from database if that item are using in another place how we can
do with in our project give some help

推荐答案

如果您想要阻止删除表中的行,如果您仍希望从另一个表中引用它,则必须在这两个表之间设置外键关系。假设表Main中的行在表Details中有一个或多个记录,那么你需要建立一个从Main表到表Details的外键关系。表格中的记录只有在不再从任何现有外键关系引用时才能删除。



见这里:创建和修改FOREIGN KEY约束 [ ^ ]



问候,



- Manfred
If you want to prevent a row in a table to be deleted if you still want to reference it from another table you'll have to set up a foreign key relationship between these two tables. Lets say rows in table Main have one or more records in table Details, then you need to establish a foreign key relation from table Main towards table Details. That way records in table Detail can only be deleted when they are no longer being referenced from any existing foreign key relation.

See here: Creating and Modifying FOREIGN KEY Constraints[^]

Regards,

— Manfred


解决方案1是最好的。此外,你应该检查元素的引用数据是否存在(需要删除)。



最近我回答了类似的问题,请查看。

处理从网格视图中删除有两个关系表 [ ^ ]



此外,请勿删除记录,更改行的状态。通过这种方式,您可以维护备份和获得更多的好处,如审计。检查下面的答案,在那里解释

Sql Table。怎么做? [ ^ ]
Solution 1 is the best one. Besides you should check the existence of referred data of the element(which need to be deleted).

Recently I have answered similar question, check it out.
Handle Delete from Grid view have 2 tables with relationships[^]

Besides, Don't delete records, Change the status of Rows. By that way, you could maintain backups & get more benefits like audit. Check the below answer, explained there
Sql Table.. How to do this?[^]


这篇关于防止从数据库中删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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