MySQLのトリガーで値セット
MySQLのトリガーで値セット create table hoge( id MEDIUMINT NOT NULL AUTO_INCREMENT, order_no CHAR(7), PRIMARY KEY (id) ); DROP TRIGGER trigger_name; DELIMITER $$ CREATE TRIGGER trigger_name BEFORE INSERT ON hoge FOR EACH ROW BEGIN declare max_id MEDIUMINT; IF NEW.order_no = "" THEN select max(id) into max_id from hoge; SET NEW.order_no := CONCAT("AA",lpad(max_id+1, 5, '0')); END IF; END; $$ DELIMITER ; insert into hoge (order_no) values(""); select * from hoge;