DELIMITER $$
CREATE TRIGGER Prevent_User_From_Insert_Empty_Strings BEFORE INSERT ON users
FOR EACH ROW
BEGIN
IF NEW.name = '' THEN
SIGNAL SQLSTATE '45000';
END IF;
END;
Last active
September 20, 2017 09:03
-
-
Save nezarfadle/0a810f5a0e2ebb1e42465324dc08110d to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example shows how to use MySQL trigger to prevent the user from adding an empty string to the name field in the users table.
This could be handy in case if we want to add another validation layer to our application ( keep in mind that this might decrease the performance a bit ).