mysqlsql-serverraiseerror

Custom errors in mysql trigger


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?


Solution

  • 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