Your code appears to be fine drop table if exists t,t1; create table t(dpid varchar(12), cpid varchar(12), qty int,cost_price decimal(10,2),sell_price decimal(10,2)); create table t1(id int auto_increment primary key); drop trigger if exists t; delimiter$$ create trigger t before insert on t for each row begin insert into t1 values (null); SET NEW.dpID = CONCAT('DP',LPAD(LAST_INSERT_ID(),1,'')); end$$ delimiter; INSERT INTO t(cpID,QTY,COST_PRICE,SELL_PRICE) VALUES ('CP6',150,999,1500); INSERT INTO t(cpID,QTY,COST_PRICE,SELL_PRICE) VALUES ('CP6',150,999,1500); select * from t; +------+------+------+------------+------------+ | dpid | cpid | qty | cost_price | sell_price | +------+------+------+------------+------------+ | DP1 | CP6 | 150 | 999.00 | 1500.00 | | DP2 | CP6 | 150 | 999.00 | 1500.00 | +------+------+------+------------+------------+ 2 rows in set (0.00 sec)