Delete in an UPDATE trigger

-1

How can I delete a record being inserted into a specific condition in a trigger?

example:

USE 'scompraslenovo';
DELIMITER $$
CREATE TRIGGER 'precad_fornecedor_BUPD' BEFORE UPDATE ON 'precad_fornecedor' FOR EACH ROW
BEGIN
    IF (new.f1 IS NULL) AND (new.f2 IS NULL) AND (new.f3 IS NULL) THEN
        DELETE FROM precad_fornecedor
        WHERE precad_fornecedor.codigo = NEW.codigo;
    END IF;
END

Is there any way to make it work?

    
asked by anonymous 17.12.2014 / 16:54

1 answer

3

"Deleting a record being inserted" does not make much sense. If you are going to delete the record you are going to insert, it is more practical not to insert it, right? So in case you would like to prevent certain records, if you do not meet the conditions, do not get inserted right? In this case, you only have to change update by insert and put the conditions.

USE 'scompraslenovo';
DELIMITER $$
CREATE TRIGGER 'precad_fornecedor_BUPD' before insert ON 'precad_fornecedor' FOR EACH ROW
BEGIN
IF ...
Where... 
END IF;
END

Before inserting, the trigger will search the conditions. If it does not, the record will not be inserted. Avoiding insertion for later deletion.

    
17.12.2014 / 17:19