Skip to content

Instantly share code, notes, and snippets.

@visabhishek
Created February 6, 2016 12:00
Show Gist options
  • Save visabhishek/42e4983f0871a26eb966 to your computer and use it in GitHub Desktop.
Save visabhishek/42e4983f0871a26eb966 to your computer and use it in GitHub Desktop.
DELIMITER $$
CREATE TRIGGER trigger1
BEFORE DELETE
ON table1
FOR EACH ROW
BEGIN
IF OLD.id = 1 THEN -- Abort when trying to remove this record
CALL cannot_delete_error; -- raise an error to prevent deleting from the table
END IF;
END
$$
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment