Skip to content

Instantly share code, notes, and snippets.

@rodurma
Created July 22, 2013 12:59
Show Gist options
  • Select an option

  • Save rodurma/6053651 to your computer and use it in GitHub Desktop.

Select an option

Save rodurma/6053651 to your computer and use it in GitHub Desktop.
Criar uma slug com o id do próprio registro no banco de dados.
DELIMITER $$
CREATE TRIGGER `create_slug` BEFORE INSERT
ON `slugs`
FOR EACH ROW
BEGIN
SET new.id = (SELECT MAX(id) FROM slugs) + 1;
SET new.slug = CONCAT(new.slug, "-", new.id);
END$$
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment