Auto Increment . .
For instances, if the column name is “Name” and the column has a value, such as “Robin Shankar,” the trigger will replace the “-” spaces and also add an auto-increment identifier to the end of the bullet, thereby creating a unique slug.
robin_shankar_9071
DELIMITER //
CREATE TRIGGER insert_slug_sd
BEFORE INSERT ON `your_table_name`
FOR EACH ROW
BEGIN
DECLARE auto_increment_ INT(11);
SELECT
`auto_increment`
INTO
auto_increment_
FROM INFORMATION_SCHEMA.TABLES
WHERE
table_name = 'your_table_name';
SET NEW.`Slug` = CONCAT(LOWER(REPLACE(NEW.`Name`,' ','-')),'-',auto_increment_);
END; //
DELIMITER;
source
share