March 18, 2010 at 5:42 am
Hi Guy's I'm having trouble trying to get my head around this one but I know it is a very simple solution. Wondering if someone could help me. I have a table with product codes and items related to the codes.
TABLE 1
Product Codes | Item Number
RP WOEWPOI
Y OWRT0W
ZZ LDSFLSGKK
I have created a second table which contains a product group. This table holds information on where the Product Codes belong. I'm not sure if I have designed this table correctly.
TABLE 2
Product Group | Product Codes | Product Codes1 | Product Codes2 |Product Codes3 .........etc etc
Tin RP TL ER AS
Metal Y ZZ
Water EF TY AS
Coffee OP RC
My aim is to create a report in where I know a particular item is related to a certain Product Group. I'm not sure if I'm going about it the right way though. I need to know how to link it if it's one to many or many to many or...I really don't know.
Your help would be much appreciated.
Jonah
March 18, 2010 at 6:04 am
from a quick look you need to normalise the second table.
en.wikipedia.org/wiki/Database_normalization
For example rather than having.
Product Group | Product Codes | Product Codes1 | Product Codes2 |Product Codes3 .........etc etc
you should have
Product Group | ProductCodeType | ProductCode
the data should then look like;
Tin 1 RP
TIN 2 TL
TIN 3 ER
etc..
then you can do a join based on the product code, and the table is a lot more flexible for future changes such as adding new Prodcut Code Type
March 18, 2010 at 6:23 am
Would the ProductType Number start over agin when there is a new product Group?
March 18, 2010 at 6:35 am
You're correct, you did not design the table correctly. What would happen if you need to add one more productcode? The entire database and the front-end would break.
Anytime that you have more then one item that relates to only one item. Such as cars and colors the car comes in. You must use an associative table.
Example:
Car
CarRowID
MakeofCar
CarName
CarColor
ColorRowID
ColorName
CarCarColor
CarRowID
ColorRowID
That way you can have many cars with many colors. And a car can come in one or more colors, and one or more colors can be on one or more cars
You should Never, Ever create a table with a long list of items like that.
Andrew SQLDBA
March 18, 2010 at 6:44 am
Aah ok. Table one cannot be changed as it's from a datasource. The primary key from this would be the Product Code.
March 18, 2010 at 7:01 am
That is fine, what ever you use. You do not have change the table. I was only giving an example. You just have to make certain that the Key will not allow a duplicate. That is difficult using text.
Andrew SQLDBA
March 18, 2010 at 7:03 am
Thanks Steve, this has helped me a lot.
Kind Regards,
Jonathan
March 18, 2010 at 7:08 am
Best normalized form could be
TABLE 1 {This is product code master}
Product Codes | Item Number
TABLE 2 {This is product group master}
Product Group ID | Product Group
TABLE 3 {This is mapping of Product Group ID and Product Codes}
Product Group ID | Product Codes
This will seperate out master informatoin and detailed mapping information. Data can be handled in better manner avioding delete anomalies
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply