We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,688 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

db modeling

Hi everybody,

I have made my ER diagram for my DB, but i want it optimized.
The db should store date for something like in attached images.

I thought about a Products table with attributes: some_primary_Key, product_id, component_id,...
The number of component is stored in another table; the question is how do i structure this dates so that i don't have to many lines in tables and redundancy.
As i made it for now i would have to many lines in Products table, a row for each component_id of a product_id; maybe a can reduce this with some db structure concept, 'cause i could have same component in more products (and reverse of course).
Should i make 2 tables? Products and Components?... please advise me. What should i google about?

Attachments date.JPG 29.02KB table.JPG 26.79KB
2
Contributors
1
Reply
21 Hours
Discussion Span
3 Years Ago
Last Updated
2
Views
sasha_3
Newbie Poster
1 post since May 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

The second way is normalised, and great simplifies querying - you don't have to search multiple columns.

Apart, that is, from your failure to recognise that product and component are a natural joint primary key. There is no need to add another unique identifier, as it will cause you problems. For example you will have to declare the combination product with component unique and force the database to check this separately from checking the unnecessary id. Declaring them as a joint primary key makes this unique check automatic, and saves the extra check on your extra id.

So your table is just the two columns product_id and component_id.

PS you should be googling on database normalisation.

drjohn
Posting Pro
508 posts since Mar 2010
Reputation Points: 76
Solved Threads: 100
Skill Endorsements: 4

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.5149 seconds using 2.66MB