Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vinibortoletto/1e3b6fdbe7072a4552475cbb92aebfbb to your computer and use it in GitHub Desktop.
Save vinibortoletto/1e3b6fdbe7072a4552475cbb92aebfbb to your computer and use it in GitHub Desktop.
Guarantee that user cannot insert a manual id on a auto_increment field
DROP TRIGGER IF EXISTS sakila.bf_insert_actor;
DELIMITER $$
CREATE TRIGGER bf_insert_actor
BEFORE INSERT ON sakila.actor
FOR EACH ROW
BEGIN
IF NEW.actor_id IS NOT NULL THEN
SET NEW.actor_id = null;
END IF;
END $$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment