0

After insert in table_user, I want the filed user_notification and user_recover are null. In this moment, this filed are blank and not null because the form send POST data same blank value.

How to create this trigger?

2
  • I think you mean: "After inserting a record in TABLE USER, I want the FIELDS user_notification and user_recover to be set to null values. At the moment, these 2 fields are set to empty strings (ie. blank, not null) because of the from sending empty strings" Commented Sep 7, 2016 at 19:53
  • A trigger is not really the correct way to solve this problem - that trigger will fire EVERY time that a record is saved or updated, affecting database performance (in a bad way!). Change the form so it does NOT pass empty strings OR remove them before saving to the database. Commented Sep 7, 2016 at 19:54

1 Answer 1

0

I have find a solution:

    delimiter $$
create trigger nullify_blanks_ins before insert on your_table
for each row begin
    if new.string = '' then
        set new.string = null;
    end if;
end;
$$
create trigger nullify_blanks_upd before update on your_table
for each row begin
    if new.string = '' then
        set new.string = null;
    end if;
end;
$$  
delimiter ;

Ref: Is there a way in MySQL to automatically convert empty string to NULL value?

Thanks for previous Answers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.