手动调用级联删除? [英] Manually call cascade delete?

查看:50
本文介绍了手动调用级联删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有 3 个表,child1"、child2"和child3",它们都有一个表parent"的外键.表parent"有一个字段status",如果一个元素的状态设置为0",它的所有子元素都会被删除.(我使用触发器来检测状态变化).所以这就像调用级联删除",但不删除对象...

Let's say I have 3 tables, "child1", "child2" and "child3", that all have a foreign key to the table "parent". Table "parent" got a field "status", and I would that if status is set to "0" for an element, all its child are deleted. (I use trigger to detect status changes). So it's like calling "cascade delete", but without deleting the object ...

有什么好办法吗?

推荐答案

触发器检测到更改,您需要使用它来触发存储过程.这是一个很好的教程:http://markalexanderbain.suite101.com/mysql-存储过程和触发器-a71091

Trigger detects the change, you need to use it to fire a stored procedure. Here's a good tutorial: http://markalexanderbain.suite101.com/mysql-stored-procedures-and-triggers-a71091

或者,如果您使用 php、coldfusion 或其他一些中间层,您可以将记录读入变量.删除该行,然后重新插入记录.但是您最好使用存储过程来完成工作.

Alternatively if you are using php, coldfusion or some other middle tier, you could read the record into a variable. Do delete the row, then re-insert the record. But you are better off with the stored procedure doing the work.

这篇关于手动调用级联删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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