CREATE TRIGGER saledetail_id BEFORE INSERT ON saledetail FOR EACH ROW BEGIN declare n int; select IFNULL(max(right(ItemID,4)),0) into n from saledetail where mid(ItemID,1,8)=DATE_FORMAT(CURDATE(),'%Y%m%d'); set NEW.ItemID=concat(DATE_FORMAT(CURDATE(),'%Y%m%d'),right(10001+n,4)); END;
//注意在插入的时候主键要设置一个默认值才能插入进去,这里我设置的是空字符串””
Maybe you could buy me a cup of coffee.
Scan this qrcode
Open alipay app scan this qrcode, buy me a coffee!
Scan this qrcode
Open wechat app scan this qrcode, buy me a coffee!