keii raven
keii raven

Reputation: 31

how to create a trigger in concatenating a 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 in concatenating the num column that has auto increment value since the trigger is for before insert cause it will show a 0 value since the auto increment is still 0 until you insert some values...can you help me???

Upvotes: 3

Views: 64

Answers (1)

juergen d
juergen d

Reputation: 204874

I suggest you don't store data again in another column that you already have in the num and letter columns.

You can generate the student_no column on-the-fly in your selects like this

select *,
       concat(letter, ' - ', num) as student_no
from your_table

Upvotes: 1

Related Questions