3

I'm trying to intercept any DELETE commands against a particular table. MySQL supports triggers but it doesn't seem to support a way to raise an error yet like SQL Server and other databases.

Can I do this with just an empty Trigger definition? Something like:

create trigger trListsDelete on lists
instead of delete
as
begin
  /* Do nothing */
end

In SQL Server I could add a RAISEERROR('You cannot delete lists.') statement to force it to fail and that way I know the Delete wouldn't be executed. Since MySQL doesn't support raising errors, how do I simply ignore the Delete command?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Wayne Molina
  • 19,158
  • 26
  • 98
  • 163
  • 1
    Looks like a duplicate of http://stackoverflow.com/questions/24/throw-error-in-mysql-trigger (raising error on update rather than delete). – Alan Jackson Oct 30 '09 at 13:21

1 Answers1

3

The technique is you do something that will cause an error, such as update a column that doesn't exist.

Details here: MySQL Triggers: How do you abort an INSERT, UPDATE or DELETE with a trigger?

Laurel
  • 5,965
  • 14
  • 31
  • 57
Alan Jackson
  • 6,361
  • 2
  • 31
  • 32