How to create a trigger in the concatenation of auto_increment value column and a column that has a default value
DELIMITER $$
CREATE DEFINER=`root`@`localhost` TRIGGER `grade_one_BINS`
BEFORE INSERT ON `grade_one` FOR EACH ROW
set new.student_no = concat(new.letter, ' - ',new.num)
there is a problem with the concatenation of a num column that has an auto-increment value as the trigger is before the insert, because it will show the value 0, since auto-increment is still 0 until you enter some values ... can you help me ?? ?
+3
keii raven
source
to share
1 answer
I suggest you don't store the data again in another column that you already have in columns num
and letter
.
You can generate a column student_no
on the fly in your chosen
select *,
concat(letter, ' - ', num) as student_no
from your_table
+1
juergen d
source
to share