dbTalk Databases Forums  

Please help with DB structure

comp.databases.ms-access comp.databases.ms-access


Discuss Please help with DB structure in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
stenogriz
 
Posts: n/a

Default Please help with DB structure - 09-09-2011 , 08:14 AM






I need to write a small DB to store product bill of materials (BOM). I made3 tables:

component: id, component_name;
// just a list of all components
assembly: id, assembly_name, isproduct;
// list of assemblies. product can consist of several assemblies - isproduct is a boolean to decide whether assembly is a final product
spec: id, assembly_id, component_id, qty;
// bill of materials itself (or specification) - stores qty of components in assemblies

One problem is that assembly itself can also be a component. And in given structure it results in the fact that component_id in spec table can hold foreign ids of two tables (component and assembly) How should i change theDB structure to overcome that problem?

Looking forward to community comments.
Thanks in advance for your answers.

Reply With Quote
  #2  
Old   
Sergei Minayev
 
Posts: n/a

Default Re: Please help with DB structure - 09-09-2011 , 02:46 PM






Thanks, Phil! After some time I came with almost the same idea. But instead of "type" variable I introduced BOOL IsAssembly - to distinguish assemblies in components table.
Now I've got another problem - I am unable to build up a query (in MS Access) for collecting data from two tables, one of which contains two columns for foreign keys from another table.

Reply With Quote
  #3  
Old   
Sergei Minayev
 
Posts: n/a

Default Re: Please help with DB structure - 09-09-2011 , 02:55 PM



<img src="https://lh4.googleusercontent.com/-x_yzVt4YF6k/TmpuchjbsrI/AAAAAAAAA-g/u2MkeK2sZbA/s800/%2525D0%252591%2525D0%2525B5%2525D0%2525B7%2525D1% 25258B%2525D0%2525BC%2525D1%25258F%2525D0%2525BD%2 525D0%2525BD%2525D1%25258B%2525D0%2525B9.PNG" />
Here is my current db structure.

Reply With Quote
  #4  
Old   
Bob Quintal
 
Posts: n/a

Default Re: Please help with DB structure - 09-09-2011 , 04:52 PM



Sergei Minayev <sergei.minayev (AT) gmail (DOT) com> wrote in
news:fc5ea70c-7dab-4f2d-a7dd-2b99271898cf (AT) glegroupsg2000goo (DOT) googlegro
ups.com:

Quote:
Thanks, Phil! After some time I came with almost the same idea.
But instead of "type" variable I introduced BOOL IsAssembly - to
distinguish assemblies in components table. Now I've got another
problem - I am unable to build up a query (in MS Access) for
collecting data from two tables, one of which contains two columns
for foreign keys from another table.
It is possible to do this.

From the menu bar, select Tools, Options, Tables/Queries.
Uncheck the "Enable Autojoin" checkbox.
Open the Query design tool.
First, show the table with the 2 foreign keys,
TblJnComponentComponent
..
Then put your other table, TblComponents.
Put your TblComponents a second time.
Access will change the name of the second copy of the table.
You can change the aliases to more meaningful ones. I use ParentItems
and ChildItems.
Draw the relationships from the first table to the second and the
first table to the third.
Select the fields you want to see in the query and save then test it.
..



--
Bob Q.
PA is y I've altered my address.

Reply With Quote
  #5  
Old   
Phil
 
Posts: n/a

Default Re: Please help with DB structure - 09-09-2011 , 08:11 PM



On 09/09/2011 20:55:23, Sergei Minayev wrote:
Quote:
img
src="https://lh4.googleusercontent.com/-x_yzVt4YF6k/TmpuchjbsrI/AAAAAAAAA-g/u2MkeK2sZbA/s800/
%2525D0%252591%2525D0%2525B5%2525D0%2525B7%2525D1% 25258B%2525D0%2525BC%2525D1%25258F%2525D0%2525BD%2 525D0%2525BD%2525D1%25258B
%2525D0%2525B9.PNG"
Quote:
/> Here is my current db structure.

Hi Sergei

Bob is spot on on the relationships you need.

Your earlier post about using a Boolean Type is that in the example I gave,
there were 3 types of components - finished components, assemplies and
alternatibe sources of those assemblies which I called Products.

In your relationship view, you do not need Id in tblSpecification.
Id_Assembly & ID_Component need to be joint keys. I stronlgly advise you hot
to use "ID" as the key to a table - you have it 3 times in 3 tables so noone
knows which ID you are referring to. Use ComponentID in the tblComponents and
MeasureID in the tblMeasurements and again as the foreign key in
tblComponents. I also query is_assembly and is_product. Not sure what
is_product is used for, but I can see a situation where both is_product and
is_assembly are both set to either true or false, and I guess if one is true,
the other is false. Sorry to be so picky, but "name" in your tblComponent is
a sort or reserved word, need surrounding with [] braces and is a pain. Use
ComponentName then you know what you are talking about.

Phil

Reply With Quote
  #6  
Old   
Joan Wild
 
Posts: n/a

Default Re: Please help with DB structure - 09-10-2011 , 08:40 AM



It isn't really necessary to change the options to do this. Create the
query, add the tables, delete the 'autojoin' lines shown, and then draw
the join lines you wish.

Joan
Bob Quintal wrote:

Quote:
It is possible to do this.

From the menu bar, select Tools, Options, Tables/Queries.
Uncheck the "Enable Autojoin" checkbox.
Open the Query design tool.
First, show the table with the 2 foreign keys,
TblJnComponentComponent
.
Then put your other table, TblComponents.
Put your TblComponents a second time.
Access will change the name of the second copy of the table.
You can change the aliases to more meaningful ones. I use ParentItems
and ChildItems.
Draw the relationships from the first table to the second and the
first table to the third.
Select the fields you want to see in the query and save then test it.
.


--

Reply With Quote
  #7  
Old   
Bob Quintal
 
Posts: n/a

Default Re: Please help with DB structure - 09-10-2011 , 12:15 PM



"Joan Wild" <jwild (AT) nospamtyenet (DOT) com> wrote in
news:xn0hixu6q0000001 (AT) nntp (DOT) aioe.org:

Quote:
It isn't really necessary to change the options to do this.
Create the query, add the tables, delete the 'autojoin' lines
shown, and then draw the join lines you wish.

Joan
While experienced users like you and I can deal with Access's being
'helpful', I've found that it often confuses neophytes.

I've also found that in a family tree structure like this one, that
it sometimes crashes when trying to add the relations.

Bob

Quote:
Bob Quintal wrote:


It is possible to do this.

From the menu bar, select Tools, Options, Tables/Queries.
Uncheck the "Enable Autojoin" checkbox.
Open the Query design tool.
First, show the table with the 2 foreign keys,
TblJnComponentComponent
.
Then put your other table, TblComponents.
Put your TblComponents a second time.
Access will change the name of the second copy of the table.
You can change the aliases to more meaningful ones. I use
ParentItems and ChildItems.
Draw the relationships from the first table to the second and the
first table to the third.
Select the fields you want to see in the query and save then test
it. .





--
Bob Q.
PA is y I've altered my address.

Reply With Quote
  #8  
Old   
Sergei Minayev
 
Posts: n/a

Default Re: Please help with DB structure - 09-11-2011 , 02:10 AM



Ok! Thanks for the advice about ID field naming. I'll try to follow it.

Reply With Quote
  #9  
Old   
Sergei Minayev
 
Posts: n/a

Default Re: Please help with DB structure - 09-11-2011 , 02:20 AM



I've got the idea. But there is no use in making separate table just for name. Cause both component and assembly can have more than 1 field in common.

Reply With Quote
  #10  
Old   
Phil
 
Posts: n/a

Default Re: Please help with DB structure - 09-11-2011 , 08:49 AM



On 10/09/2011 18:15:41, Bob Quintal wrote:
Quote:
"Joan Wild" <jwild (AT) nospamtyenet (DOT) com> wrote in
news:xn0hixu6q0000001 (AT) nntp (DOT) aioe.org:

It isn't really necessary to change the options to do this.
Create the query, add the tables, delete the 'autojoin' lines
shown, and then draw the join lines you wish.

Joan

While experienced users like you and I can deal with Access's being
'helpful', I've found that it often confuses neophytes.

I've also found that in a family tree structure like this one, that
it sometimes crashes when trying to add the relations.

Bob

Bob Quintal wrote:


It is possible to do this.

From the menu bar, select Tools, Options, Tables/Queries.
Uncheck the "Enable Autojoin" checkbox.
Open the Query design tool.
First, show the table with the 2 foreign keys,
TblJnComponentComponent
.
Then put your other table, TblComponents.
Put your TblComponents a second time.
Access will change the name of the second copy of the table.
You can change the aliases to more meaningful ones. I use
ParentItems and ChildItems.
Draw the relationships from the first table to the second and the
first table to the third.
Select the fields you want to see in the query and save then test
it. .

Sorry, Bob & Joan
This has nothing to do with queries. The joins originally need to be set in
the relationships with referential integrity enforced. I grant you then when
you subsequently design a query, you need to sort out the joins from the 2
copies of the TblComponents to TblJnComponentComponent which should be the
same as shown in the relationships. The default name of the 2 copies of
TblComponents will be TblComponents and TblComponents_1. Make sure you join
ComponentID from TblComponents to Component1ID in TblJnComponentComponent and
ComponentID from TblComponents_1 to Component2ID in TblJnComponentComponent

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.