mysql触发器生成流水_利用mysql触发器生成流水号
http://blog.csdn.net/bluestream/article/details/5755176
利用mysql觸發器可以生成如日期(20100721)+編號(0001)的流水號,編號每天都會從0001開始計算
create table orders(orders_id int(10) primary key,customer_name varchar(100)?);
----------------------------------------------------------------------------------------------------------
CREATE TRIGGER tr_orders_id BEFORE INSERT ON orders
FOR EACH ROW BEGIN
declare n int;
select IFNULL(max(right(orders_id,4)),0) into n from orderswhere mid(orders_id,1,8)=DATE_FORMAT(CURDATE(),'%Y%m%d');
set NEW.orders_id=concat(DATE_FORMAT(CURDATE(),'%Y%m%d'),right(10001+n,4));
END;
----------------------------------------------------------------------------
insert into test(customer_name) value('jack');
insert into test(customer_name) value('jason');
-----------------------------------------------------------------------------
orders_id??????????????? customer_name
201007210001?????????????? ?jack
201007210002????????????????jason
.
總結
以上是生活随笔為你收集整理的mysql触发器生成流水_利用mysql触发器生成流水号的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android app 移植到pc,微软
- 下一篇: Oracle 多表查询 --笛卡尔集--