How to reject delete statement in before delete trigger?

六眼飞鱼酱① 提交于 2019-12-02 19:25:56

问题


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

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


回答1:


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.

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.




回答2:


Look here, same thing but with an insert-trigger: How to abort INSERT operation in MySql trigger?



来源:https://stackoverflow.com/questions/5132356/how-to-reject-delete-statement-in-before-delete-trigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!