Custom errors in mysql trigger [duplicate]

▼魔方 西西 提交于 2019-12-23 05:41:46

问题


Possible Duplicate:
raise error within MySql function

In MsSQL I can raise a custom error:

CREATE TRIGGER [dbo].[TR__TABLE__DisableRowOnDelete]
ON [dbo].[TABLE]
INSTEAD OF DELETE
AS 
BEGIN
    RAISERROR ('Data cannot be deleted.', 16, 1);
END

How might I do that in MySQL?


回答1:


In MySQL 5.5 you can use a SIGNAL statement, e.g. -

CREATE PROCEDURE TR__TABLE__DisableRowOnDelete()
BEGIN
  SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Data cannot be deleted.';
END


来源:https://stackoverflow.com/questions/8913999/custom-errors-in-mysql-trigger

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