thanasis2028
thanasis2028

Reputation: 125

How to suppress insert in mysql

I want to create a BEFORE CREATE TRIGGER that checks if some restrictions apply, and if they don't, it stops the row from being added. I know i can access specific values of the added item with the NEW keyword, but how can i command mysql to suppress the insertion?

Upvotes: 0

Views: 56

Answers (1)

Thanga
Thanga

Reputation: 8101

Inside your trigger You can stop your insert using SIGNAL keyword as below

  if(<your condition>) then
     SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'your error message';
  end if 

This will stop inserting

Upvotes: 2

Related Questions