Custom errors in mysql trigger [duplicate]

2019-06-13 02:15发布

问题:

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