简体   繁体   中英

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.

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.

Payment information (payment method, transaction id, timestamp, etc) will also be stored.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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