views:

138

answers:

3

ok im new to database design, please give me advices about this.

1 http://stackoverflow.com/questions/1823685/database-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 http://stackoverflow.com/questions/1277865/mysql-indexes-how-many-are-enough/1277986#1277986

is it just enough ?

3 http://stackoverflow.com/questions/3282510/database-normalization

is it just right?

alt text

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

+5  A: 

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.

thomasrutter
anyway i got a problem now, how can i insert a new company ? where should do i get the CID before im inserting the CID ?
kaskus
+1  A: 

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.

kdmurray
I wouldn't think this is necessary; how would having CID and UID as the primary key depend too much on the structure of other tables? Wouldn't adding another key de-normalise it to some extent?
thomasrutter
This is to some degree an "opnion" question. I suppose it depends on the context of the project and whether the CID and UID are exposed as "business data". A table's key should be an internal-only piece of data that's simply used to key records in a table.Multi-field keys can also make for more complex logic when working with the table.
kdmurray
hmm i so would like to do that, but they do have limits ( mapping_id as a int ), and do i have to add unique to each PK ? or PK and unique are quite the same ?
kaskus
PKs are by definition unique. If you have other fields that you'd want to keep unique you can add a unique constraint to those as well.
kdmurray
+3  A: 

No good.

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

Paul
I guess whether or not a database is over-designed depends on the spec ie what it is intended/required to do, and we don't really know that from the question. If you only need one large and one small image of each product then designing for multiple images per product would be over-designing. So this really depends on what the requirements for the app really are. It's a question worth taking back to the client/boss I guess :)
thomasrutter
how do i do that ?
kaskus
Add another table: `images`, having [product_id, img_small, img_large]. You'll join with "product LEFT JOIN image ON (product.id=image.product_id)". Products w/o an image will have null values for img_small and img_large. Products with multiple images will have be listed in rows with different img_small and img_large values.
Paul