Re: relational db design question

From: Walt <wamitty_at_verizon.net>
Date: Sun, 11 Feb 2007 22:14:05 GMT
Message-ID: <NyMzh.2977$7s2.2636_at_trndny07>


<chezball_at_gmail.com> wrote in message news:1170961518.911571.61730_at_l53g2000cwa.googlegroups.com... <quote>
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
<unquote>

Perhaps it would be useful if you told us exactly what you find aethecially unpleasant about the design you offered to us.

Does it fail to meet the information requirements? Is it too difficult for a new person to understand (or for yourself, after a suitable interval)?
Is it too difficult to write queries against? Is it too difficult to write updates for? Do expect it to create performance problems?

In short, what makes a design "pretty" or "ugly"?

In the meantime, in addition to looking up "subtypes" you should look up "relational model generalization specialization". Essentially you have several specialized types of reference, which can all be generalized to "reference". Received on Sun Feb 11 2007 - 23:14:05 CET

Original text of this message