Did I overdesign my MySQL database (users/companies/products)?

旧城冷巷雨未停 提交于 2020-01-02 02:27:10

问题


I'm new to database design, please give me advice about this.

1 When should I use a composite index?

im not sure what does index does, but i do know we should put it when it will be heavly loaded like for WHERE verified = 1 and in search like company.name = something. am i right ?

2 MySQL indexes - how many are enough?

is it just enough ?

3 Database Normalization

is it just right?

Thanks.

edit*

rules.

  1. each users( company member or owners ) could be a member of a company
  2. each company have some member of users.
  3. there are company admins ( ceo, admins) and there are company members ( inserts the products )
  4. each company can have products.

for the number 3 i will add a bit at users_company - 1 is for admin - 0 is for members


回答1:


Looks good, well normalised, to me at least.

I notice that each product can only belong to one company. If that's what you intended that's fine, otherwise you could have product have its own PID and have a product_company relation table, which would let more than one company sell a particular product. Depends who administers the products I guess.

I did notice that the user table is called 'users' (plural) and the others are singular ('company', 'product'). That's only a minor thing though.




回答2:


No good.

Example: I want multiple pictures of my product. Please let me upload more than one picture of my product!




回答3:


The only comment I have is that you may want to consider just adding a mapping_id column to your users_company table and making CID and UID foreign keys, and add a UNIQUE constraint.

This way you can have a distinct Primary Key for records in that table which isn't dependent on the structure of your other tables or any of your business logic.



来源:https://stackoverflow.com/questions/3305825/did-i-overdesign-my-mysql-database-users-companies-products

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!