I have the following MySQL table named users
+----------------+----------------+----------+ +----------+
| uniquenum | state | type | | custid |
+----------------+----------------+----------+ +----------+
+----------------+----------------+----------+ +----------+
| 00001 | 03 | 1 | | 10300001 |
+----------------+----------------+----------+ +----------+
| 00002 | 02 | 3 | | 30200002 |
+----------------+----------------+----------+ +----------+
The above three columns uniquenum, state and type are all concatenated and shown in the custid column. This I was able to achieve by running the following SQL query:
UPDATE users SET custid = concat (type,state,uniquenum)
What I am trying to achieve is to make the custid column to automatically get the values of the other three columns when new values are added or the old ones updated. So, I tried to create a trigger as follows:
CREATE trigger insert_custid
before insert on users
for each row
set new.custid = concat(new.type,new.state,new.uniquenum);
create trigger update_custid
before update on users
for each row
set new.custid = concat(new.type,new.state,new.uniquenum);
When I do this and insert into the table, the custid column does not store the correct values. Instead it returns all zeros in place of the value of uniquenum. uniquenum is AUTO_INCREMENT with zerofill and starts at 00001 with an interval of 1. Could this be causing an issue? Any help is greatly appreciated. Thank you :)