How to reject delete statement in before delete trigger?

后端 未结 2 746
無奈伤痛
無奈伤痛 2021-01-28 03:45

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

Sample use case : I have a record with specified id that I w

2条回答
  •  北海茫月
    2021-01-28 04:23

    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.

提交回复
热议问题