简体   繁体   English

MySQL产品销售模式

[英]MySQL Product Sale Schema

I'm in the process of creating a website and would like some advise on my database schema as I don't have very much experience in that field. 我正在创建一个网站,并希望对我的数据库架构提供一些建议,因为我在该领域没有太多经验。

Say I had a site where 2 products were for sale, product1 and product2. 假设我有一个要出售2种产品(product1和product2)的站点。

When a user buys either product they get a user account with a key to access their account. 当用户购买任何一种产品时,他们都会获得一个具有访问其帐户密钥的用户帐户。 A user can download their product from their account page. 用户可以从其帐户页面下载其产品。 That user can then at a later date purchase the remaining product and the product gets added to their account allowing them to download both product1 and product2 using the key given to them when purchasing the first product. 然后,该用户可以在以后购买剩余的产品,并且该产品会添加到他们的帐户中,从而允许他们使用购买第一个产品时提供给他们的密钥来下载product1和product2。

Payment information (payment method, transaction id, timestamp, etc) will also be stored. 付款信息(付款方式,交易ID,时间戳等)也将被存储。

I currently have my schema planned as so: 目前,我已经计划好了架构:

在此处输入图片说明

I feel that the way I'm doing it is not optimal and there are better ways to organize it. 我觉得我做的方式不是最佳的,有更好的组织方式。 Any advise? 有什么建议吗?

Hope you can help and thanks in advance :) 希望您能有所帮助,并在此先感谢:)

It is a good idea to start off identifying the objects your schema will store. 最好先确定您的架构将存储的对象。 It looks like candidate components might be 看起来候选组件可能是

  • user 用户
  • (user data) (用户数据)
  • product 产品
  • purchase 采购

These entities will be the tables you start out with. 这些实体将是您开始使用的表。 Add relationships appropriately. 适当添加关系。

Identifying the entities in your schema will (hopefully) keep you from outwardly expanding tables. 标识架构中的实体将(希望)阻止您向外扩展表。 You don't want to have to revise your whole schema for example every time you add a product. 例如,您不需要每次添加产品时都修改整个架构。 Similarly, you would not want to add a new table each time. 同样,您不想每次都添加一个新表。

Once you've identified these, start putting them in normal form . 一旦确定了这些内容,就开始将它们放入标准格式 3rd normal form is generally recommended. 通常建议使用第三范式。 You will likely find, as you have indicated in your schema, there is much redundant data that would fall under the purchase entity that separating it out to another table makes for a more maintainable schema. 正如您在架构中所指出的那样,您可能会发现,采购实体下会存在大量冗余数据,这些冗余数据将其分离到另一个表中,从而形成了更易于维护的架构。

This will eliminate redundant data in your tables which might later fall out of synch and help to identify where some data is out of place. 这将消除表中的冗余数据,这些数据以后可能会失去同步性,并有助于识别某些数据在何处不正确。

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

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