Created
August 20, 2016 13:18
-
-
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'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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