Answer the question
In order to leave comments, you need to log in
How to use auto_increment field value in MariaDB 10.1 in insert trigger?
Hi everybody!
Task : when adding a new line, it is necessary that the specified field is automatically filled with the value from the auto_increment field.
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
)
CREATE TRIGGER `name_default` BEFORE INSERT ON `users`
FOR EACH ROW IF ISNULL(NEW.name) THEN
SET NEW.name = CONCAT('Player', NEW.id);
END IF
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question