我正在制作一个发票软件,我希望它保存每个单独的发票。
用户通过选择客户来创建发票,以及向客户收取多少项目费用。鉴于大多数发票将有多个项目,将它们保存到数据库中而又不会出现令人难以置信的冗余的最佳方法是什么?如果需要,我愿意重新安排我的整个数据库。
我的表是这样的:
客户表:
Id / Primary key
FullName
Address
Phone
项目表(提供的产品表):
Id / Primary key
ItemName
Price
Description
发票表(已保存的发票):
Id / Primary key
CustId / Foreign key is Id in Customer table
ItemId / Foreign key is Id in Item table
Notes
最佳答案
您需要另一个表来存储发票(您所说的 Invoices
现在实际上存储了发票项目)。
Customer
id
name
etc.
Item
id
name
etc.
Invoice
id
cust_id
date
InvoiceItem
id
inv_id
item_id
这是使用连接表(即
InvoiceItem
)对 many to many relationship 建模的经典方法。