如何在删除触发器之前拒绝删除语句? [英] How to reject delete statement in before delete trigger?

查看:260
本文介绍了如何在删除触发器之前拒绝删除语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在删除触发器之前在拒绝删除语句(mysql)?

How to reject delete statement in before delete trigger (mysql) ?

示例用例:我有一个记录,该记录具有指定的 id ,我希望将其删除.

Sample use case : I have a record with specified id that I want to will not be deleted.

推荐答案

您可以创建一个表,该表使用引用ID列(假定是表的主键)的外键约束.在引用ID = 0的子"表中插入一行,并从该表中删除用户的所有更新/删除特权.

You could create a table that uses a foreign key constrait referencing your ID column (provided that is the primary key of your table). The insert a row into that "child" table that references ID = 0 and remove all update/delete privileges for your user from that table.

现在,如果有人尝试删除父"表中ID = 0的行,由于另一表中已有子行,该行将失败.

Now if someone tries to delete the row with ID = 0 in the "parent" table that will fail due to an existing child row in the other table.

这篇关于如何在删除触发器之前拒绝删除语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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