繁体   English   中英

MySQL(数据库设计)-存储每个财政年度从1开始的发票,即4月1日

[英]Mysql(db design) - storing invoices that starts from 1 each financial year i.e. 1 april

create table invoices(
   year           int not null
  ,invoice_number int not null auto_increment
  ,primary key(year, invoice_number)
);

insert into invoices(year) values(2009);
insert into invoices(year) values(2009);
insert into invoices(year) values(2009);

insert into invoices(year) values(2010);
insert into invoices(year) values(2010);
insert into invoices(year) values(2010);

select * 
  from invoices;

+------+----------------+
| year | invoice_number |
+------+----------------+
| 2009 |              1 |
| 2009 |              2 |
| 2009 |              3 |
| 2010 |              1 |
| 2010 |              2 |
| 2010 |              3 |
| 2011 |              1 |

发票应从每年的4月1日自动生成,我已经创建了此类表格,但它将从1月1日开始生成,我想从4月1日开始

您应该存储实际的日历日期和财政年度。 可以使用触发器来插入/更新财务年度(从2009-04-01到2010-04-01的“ 2009”)(编辑:AFTER错误,BEFORE对于auto_increment来说很重要) BEFORE INSERT / BEFORE UPDATE 我不知道如何在索引的第二部分上自动增量,但是如果它与“ 2009”年一起工作,那么它也应该与2009财政年度一起工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM