MYSQL具有静态值和动态值的表 [英] MYSQL Table with static values and dynamic values

查看:110
本文介绍了MYSQL具有静态值和动态值的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,我正在创建发票功能。
发票具有静态信息:公司信息和Receiver信息。
但是它也有动态信息:小时数,说明,总金额等。
客户可以添加多行与上面的动态信息。

On my website I'm creating an invoice function. An invoice has static information: Company info and Receiver info. But it also has dynamic info: Amount of hours, Description, Total Amount etc.. Clients can add multiple rows with the dynamic info above.

现在我的问题是,
如何实现这个到我的数据库?

Now my question is, How do i implement this into my database?

现在我有一个表称为发票将拥有上述所有信息。
但是这样,行会有不必要的信息,例如公司和接收者的信息,实际上只需要为每个发票插入一次。

At the moment i have a table called "invoice", with columns that will have all the information above. But in this way, rows will have unnecessary information like the company and receiver info, that actually only has to be inserted once per invoice.

我想避免使用两个表,但如果没有其他选项,那么我会。

I would like to avoid using 2 tables, but if there is no other option, then i will.

问候

推荐答案

如果你想要一个完全关系型的数据库,第二表。这将保存客户信息。然后,此键将成为发票表中的外键,因此您只需存储一次客户信息。这将是实现类似这样的建议方式。

If you want a fully relational database, then you will need to create a second table. This would hold the customer information. This key then becomes a foreign key in your Invoice table, so you only have store the customer information once. This would be the recommended way of implementing something like this.

另一种方式(我不推荐这),你需要创建一个循环引用父发票(存储客户信息的发票)。然后,每次创建新的发票时,都必须插入父记录ID,以便您可以检索存储的信息。对于同一客户的所有其他发票,您只需将该信息留空即可。

The other way (and I don't recommend this) is that you would need to create a circular reference to the "parent" invoice (the one that stores the customer info). Then, each time you create a new invoice you would have to insert that parent record ID, so you have a way to retrieve the stored information. For all other invoices for the same customer, you would simply leave that information blank.

这篇关于MYSQL具有静态值和动态值的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆