Custom errors in mysql trigger [duplicate]

2019-06-13 02:11发布

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条回答
Summer. ? 凉城
2楼-- · 2019-06-13 03:09

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
查看更多
登录 后发表回答