简体   繁体   中英

How to reject delete statement in before delete trigger?

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.

看这里,是一样的东西,但是带有一个插入触发器: 如何在MySql触发器中中止INSERT操作?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM