I have a table member. I want to make an user id using auto increment.
I have tried using the following:
SET new.user_id = CONCAT(new.name, LPAD((SELECT AUTO_INCREMENT FROM
information_schema.TABLES WHERE
TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'member'),3,'0'));
But when I inserted a new member, i’ve got an error message user_id cannot be null and the data wasn’t added. I want the user id will shown like jos001 as an primary key.
Please help me.. how to make it happen?
Try this BEFORE INSERT trigger –
Full script:
Insert some records:
Check result: