A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

table design question



 
 
Thread Tools Display Modes
  #1  
Old February 8th, 2007, 07:07 PM posted to microsoft.public.access.tablesdbdesign
[email protected]
external usenet poster
 
Posts: 2
Default table design question

Hello,
I have a relational database design question that I cannot seem to
solve in an aesthatically pleasingly way; I was hoping someone could
help me with.

I am trying to create a recipe database, in which I would like to
associate each recipe with a reference (the reference can be a book,
newspaper, person, magazine, etc...) Because each reference is so
different, and can be used multiple times, I have broken a single
reference into two tables.

For instance, a Cook Book reference is:
· Table: Authors { AuthorID, AuthorName }
· Table: BookAuthors { BookID, AuthorID, (OPTIONAL) NameOrder }
· Table: Books { BookID, Title}
· Table: BookReference { RefID, BookID, PageNumber, OtherInfo }

The same would be done for Magazines, Newspapers, and People, with the
*Reference table being the most interesting (to this discussion) one
to change:
· Table: PeopleReference { RefID, PersonID,
InfoOnWhyPersonGaveYouThisRecipe }
· Table: NewspaperReference {RefID, NewspaperID, Date, Section/Page }
· Table: MagazineReference {RefID, MagID, Date, Page }

So, my question, which I am sure you are already answering, is how do
I map these RefID's to my Recipe, when each one will be a primary key,
incremented in autonomy? The direction I am heading, which makes me
shutter like fingers screaching down a chalkboard, is to make my
Recipe Table look like:
· Table: Recipes {RecipeID, Name, ..., RefID, RefTable, ... }
· Where RefID (refers to any RefID in any *Reference table) and
RefTable identifies which table

That is, should I store the RefTable type in the Recipe Table?

Alternatively, but equally as ugly, I could break the info out into
another table (but honestly don't know what that saves).

If this is not the way to do this (and I am hoping it is not), what is
the correct way to design this?

If this IS the way to do this then my next question is, how does one
do lookups based upon this info? What would the SQL statement that
would return all the relevant information about, say a cookbook, be?

Thanks

  #2  
Old February 8th, 2007, 10:27 PM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default table design question

On 8 Feb 2007 11:07:24 -0800, wrote:

So, my question, which I am sure you are already answering, is how do
I map these RefID's to my Recipe, when each one will be a primary key,
incremented in autonomy? The direction I am heading, which makes me
shutter like fingers screaching down a chalkboard, is to make my
Recipe Table look like:
· Table: Recipes {RecipeID, Name, ..., RefID, RefTable, ... }
· Where RefID (refers to any RefID in any *Reference table) and
RefTable identifies which table

That is, should I store the RefTable type in the Recipe Table?

Alternatively, but equally as ugly, I could break the info out into
another table (but honestly don't know what that saves).


This seems to be a classic case of "Subclassing" - one of the few
instances where one-to-one relationships are appropriate!

You have a class of entities - References - which share some
information in common; each member of this class is also a member of a
Subclass - e.g. the Class of References has some members which are
Magazine references, some which are Cookbook references, etc.

What you can do is have a References table with an autonumber RefID,
joined one-to-one to tables with the fields needed for the subclasses.
These tables would have a Long integer RefID as a primary key. You may
want some code to (say) prevent a given reference from appearing in
more than one subclass table - or you might not, if you find the same
recipe in two or more sources!

Your Recipe table would have a foreign key to the (master) References
table; your reports would have the References table left-joined to
each of the subclass tables to display whatever information is there.

John W. Vinson [MVP]
  #3  
Old February 17th, 2007, 06:26 AM posted to microsoft.public.access.tablesdbdesign
[email protected]
external usenet poster
 
Posts: 2
Default table design question

On Feb 8, 2:27 pm, John W. Vinson
wrote:
On 8 Feb 2007 11:07:24 -0800, wrote:

So, my question, which I am sure you are already answering, is how do
I map these RefID's to my Recipe, when each one will be a primary key,
incremented in autonomy? The direction I am heading, which makes me
shutter like fingers screaching down a chalkboard, is to make my
Recipe Table look like:
· Table: Recipes {RecipeID, Name, ..., RefID, RefTable, ... }
· Where RefID (refers to any RefID in any *Reference table) and
RefTable identifies which table


That is, should I store the RefTable type in the Recipe Table?


Alternatively, but equally as ugly, I could break the info out into
another table (but honestly don't know what that saves).


This seems to be a classic case of "Subclassing" - one of the few
instances where one-to-one relationships are appropriate!

You have a class of entities - References - which share some
information in common; each member of this class is also a member of a
Subclass - e.g. the Class of References has some members which are
Magazine references, some which are Cookbook references, etc.

What you can do is have a References table with an autonumber RefID,
joined one-to-one to tables with the fields needed for the subclasses.
These tables would have a Long integer RefID as a primary key. You may
want some code to (say) prevent a given reference from appearing in
more than one subclass table - or you might not, if you find the same
recipe in two or more sources!

Your Recipe table would have a foreign key to the (master) References
table; your reports would have the References table left-joined to
each of the subclass tables to display whatever information is there.

John W. Vinson [MVP]


Thank you. This is exactly what I was looking for.

 




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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:05 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.