Skip to content

Instantly share code, notes, and snippets.

@brendomaciel
Created August 20, 2016 13:18
Show Gist options
  • Save brendomaciel/cd37fc2c8aebc3029f7411d661df7bc7 to your computer and use it in GitHub Desktop.
Save brendomaciel/cd37fc2c8aebc3029f7411d661df7bc7 to your computer and use it in GitHub Desktop.
Trigger para gerar um UUID no momento da inserção de uma linha em 'table'
DELIMITER $$
USE `database` $$
DROP TRIGGER IF EXISTS `set_uuid` $$
CREATE DEFINER = CURRENT_USER
TRIGGER `set_uuid`
BEFORE INSERT ON `table`
FOR EACH ROW
BEGIN
IF ASCII(NEW.id) = 0 THEN
SET NEW.id = UUID();
END IF;
SET @last_uuid = NEW.id;
END
$$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment