0

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?

Community
  • 1
  • 1
weston
  • 54,145
  • 21
  • 145
  • 203
  • See http://stackoverflow.com/questions/465727/raise-error-within-mysql-function – Jivings Jan 18 '12 at 16:52
  • @weston before making the question see if already exists in SO. – aF. Jan 18 '12 at 16:57
  • 1
    @aF I'm glad I didn't, or I wouldn't have found out about SIGNAL – weston Jan 18 '12 at 16:59
  • 1
    @aF. Note that the other question highlighted is 3 years old with no accepted answer. So I think it was acceptable to ask this again. (Although I don't deny totally missing it when looking though the list of matching questions). – weston Jan 18 '12 at 18:24

1 Answers1

3

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
Devart
  • 119,203
  • 23
  • 166
  • 186