CREATE
TABLE
Order(order_id
VARCHER
(12) PRIMARY
KEY
, name
VARCHER
(100) );
delimiter $$
CREATE TRIGGER tr_order_id BEFORE INSERT ON `Order`
FOR EACH ROW
BEGIN
declare n int;
if n is null then
begin
set n=1;
end;
end if;
set NEW.id=concat('LQ',DATE_FORMAT(CURDATE(),'%Y%m%d%H%M'),right(10000+n,4));
END;
$$
delimiter;