You can do this in MySQL 5.5 with the SIGNAL
syntax in a TRIGGER
.
Source: http://dev.mysql.com/doc/refman/5.5/en/signal.html
You can do it then with the following TRIGGER
:
create trigger mytable_zero_check
before insert on my_table
for each row
begin
if(new.mynum = 0) then
SIGNAL 'your error message'
end if
end
If you are running < 5.5, then you can make a syntax error (for example assigning NULL
to a field that does not allow NULL
s), and the INSERT
will be aborted aswell.