如何确保用MySQL后端访问前端删除子记录? [英] how to ensure delete child records with MySQL back end Access front end?

查看:51
本文介绍了如何确保用MySQL后端访问前端删除子记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回到另一个问题。


我有一个包含子表单的表单也有子表单。 MySQL中的表格:


dpr = dpr_id(pk)等

dpr_survey = survey_id(pk),dpr_id等

dpr_cr = cr_id(pk),survey_id等。


在三个表格中的每一个表格上都有一个用于删除当前记录的删除按钮。它适用于父记录,但不适用于子记录。我为dpr_survey和dpr_cr设置了关系,但只在访问关系工具中设置。


这是删除按钮上的代码:

Back with another question.

I have a form with a subform that also has a subform. Tables in MySQL:

dpr = dpr_id (pk), etc.
dpr_survey = survey_id (pk), dpr_id, etc.
dpr_cr = cr_id (pk), survey_id, etc.

On each of the three forms is a delete button to delete the current record. It works well for the parent record but not the child record(s). I have relationships set up for dpr_survey and dpr_cr but only in the access relationships tool.

Here is the code on my delete button:

展开 | 选择 | Wrap | 行号

推荐答案

您可能需要考虑一些注意事项。

盲目删除儿童可能是一场灾难删除父项时,除非您完全了解自己在做什么。我总是设置我的数据库,以防止在存在子记录时删除父级。用户将收到警告,说明由于存在相关记录而无法删除记录。如果您有许多人使用您的数据库,则尤其如此。

最便捷的方式,如果您可以访问MySQL数据库的设计,则可以创建一个约束来级联删除。因此,当你有一个删除父项的查询操作时,MySQL也会删除子项。

如果没有这样的约束,你需要获取父项的主键然后运行查询子表将删除具有该父主键的记录。
There are some considerations here you might want to look at.
It could be a disaster to blindly delete childrens when you delete a parent unless you are fully aware of what you are doing. I always set up my databases to prevent the deletion of a parent if a child record exists. The user would get a warning saying the record cannot be deleted because a related record exists. This is particularly true if you have many people using your database.
The most expedient way, and if you have access to the design of the MySQL database, you could create a constraint to cascade delete. So when you have a query action to delete a parent, MySQL will delete the childrens too.
If there is no such constraint, you would need to get the primary key of the parent then run a query in the children table that would delete the records that have that parent primary key.


我对MySQL很新。你如何设置级联?我注意到关系构建器的Access端没有该选项。


再次感谢您的帮助。 : - )
I''m fairly new to MySQL. How do you set up cascading? I noticed that option was not available on the Access side of the relationship builder.

Thanks again for your help. :-)


这并不让我感到惊讶。我怀疑你可以使用Access来设计MySQL数据库。您可能必须转向MySQL Designer或通过MySQL命令提示符更改结构。如何建立关系,因为你提到你在原帖上建立了关系?
That does not surprise me. I doubt you can use Access to design MySQL database. You will probably have to turn to MySQL Designer or alter the structure through the MySQL command prompt. How were relationship set up initially, because you mention you have relationship established on your original post?


这篇关于如何确保用MySQL后端访问前端删除子记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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