问题
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.
- each users( company member or owners ) could be a member of a company
- each company have some member of users.
- there are company admins ( ceo, admins) and there are company members ( inserts the products )
- 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