 |
|
 |
|
Next: An encouraging note to hopeless DBA's
|
| Author |
Message |
External

Since: May 29, 2008 Posts: 7
|
(Msg. 16) Posted: Sun Jun 01, 2008 6:47 am
Post subject: Re: Multiple tables refer to one -To use foreign keys or not? [Login to view extended thread Info.] Archived from groups: comp>databases>theory (more info?)
|
|
|
On 1 jun, 00:13, "Tony Toews [MVP]" wrote:
> Adriano Varoli Piazza wrote:
>
> >We have an "attachments" table, which can refer to "works_of_art",
> >"people", "reproductions" (Let's say, more than three tables). So a
> >work of art can have attachments, a person can have a different
> >attachment, etc.
>
> What is an attachment? I can understand the works of art, people and reproductions
> but I don't know what you mean by attachment.
>
An image, document or other file related to the entity in question.
For a work_of_art, an image of a reproduction, a pdf copy of the
invoice would be attachments. For a reproduction, a scan of the page
in question where the work_of_art was reproduced (this is contrived,
yes), for a person, a picture, a music file...
Saludos
Adriano >> Stay informed about: Multiple tables refer to one -To use foreign keys or not? |
|
| Back to top |
|
 |  |
External

Since: Nov 15, 2007 Posts: 1217
|
(Msg. 17) Posted: Sun Jun 01, 2008 9:05 pm
Post subject: Re: Multiple tables refer to one -To use foreign keys or not? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Adriano Varoli Piazza wrote:
>> >We have an "attachments" table, which can refer to "works_of_art",
>> >"people", "reproductions" (Let's say, more than three tables). So a
>> >work of art can have attachments, a person can have a different
>> >attachment, etc.
>>
>> What is an attachment? I can understand the works of art, people and reproductions
>> but I don't know what you mean by attachment.
>>
>
>An image, document or other file related to the entity in question.
>For a work_of_art, an image of a reproduction, a pdf copy of the
>invoice would be attachments. For a reproduction, a scan of the page
>in question where the work_of_art was reproduced (this is contrived,
>yes), for a person, a picture, a music file...
Ah, a file attachment. Too obvious. <smile>
I did almost exactly what you propose in a fleet management system. I have one
table with a primary autonumber field (this is in Access), foreign keys pointing to
the two other equipment and service order tables, a user entered date and description
of attachment and the file extension.
An example of a file associated with a unit might be a scan of the vehicle
registration, commercial inspection by a licensed mechanic or photographs.
An example of the file associated with a service order might be a scan of a external
invoice for windshield change or transmission work.. Or maybe some photos of the
failed part.
The user was presented with a form listing all the files in their Incoming folder.
They could view the attachments or process them. Processing involved associating the
attachment with a particular unit or a service done on that unit. I then moved the
file from their incoming folder into a network folder. I also renamed the file so it
had the same value as the table's autonumber key although with leading zeros.
The file extension is required so the operating system can choose whatever software
the user has installed to view that file.
I also had some fields allowing the user to optionally choose photo's which will be
viewed in the app screens and on selected reports.
Now anyone can go into the system and view all scanned documents, photo's or other
files assocated with each unit or service. No need to rummage around various file
folders looking for specific invoices or other documents.
Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/ >> Stay informed about: Multiple tables refer to one -To use foreign keys or not? |
|
| Back to top |
|
 |  |
External

Since: Nov 15, 2007 Posts: 1217
|
(Msg. 18) Posted: Sun Jun 01, 2008 9:10 pm
Post subject: Re: Multiple tables refer to one -To use foreign keys or not? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Bob Badour wrote:
>Fundamentals first. Experience later. A person can work in this field
>for 20 years and gain a year's experience 20 times, or a person can work
>in this field for 20 years and gain 20 years experience.
>
>Sadly, one can find too many of the former and too few of the latter. In
>fact, the former abound.
Adriano
I stongly suspect Bob views me in the former category. Which doesn't bother me in
the slightest.
Bob has marked my postings to be ignored so he won't read my reply. As far as I
know he is the only person who has ever kill filed me in the newsgroups. Judging by
his other replies though I view his action as a badge of honour and worthy of
distinction.
Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/ >> Stay informed about: Multiple tables refer to one -To use foreign keys or not? |
|
| Back to top |
|
 |  |
External

Since: Oct 31, 2006 Posts: 177
|
(Msg. 19) Posted: Sun Jun 01, 2008 9:10 pm
Post subject: Re: Multiple tables refer to one -To use foreign keys or not? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"Tony Toews [MVP]" wrote:
>Bob Badour wrote:
>
>>Fundamentals first. Experience later. A person can work in this field
>>for 20 years and gain a year's experience 20 times, or a person can work
>>in this field for 20 years and gain 20 years experience.
>>
>>Sadly, one can find too many of the former and too few of the latter. In
>>fact, the former abound.
>I stongly suspect Bob views me in the former category. Which doesn't bother me in
>the slightest.
>
>Bob has marked my postings to be ignored so he won't read my reply. As far as I
>know he is the only person who has ever kill filed me in the newsgroups. Judging by
>his other replies though I view his action as a badge of honour and worthy of
>distinction.
Why how precious. Plonked.
Sincerely,
Gene Wirchenko
Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices. >> Stay informed about: Multiple tables refer to one -To use foreign keys or not? |
|
| Back to top |
|
 |  |
External

Since: Nov 15, 2007 Posts: 1217
|
(Msg. 20) Posted: Mon Jun 02, 2008 1:01 am
Post subject: Re: Multiple tables refer to one -To use foreign keys or not? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Gene Wirchenko wrote:
>>Bob has marked my postings to be ignored so he won't read my reply. As far as I
>>know he is the only person who has ever kill filed me in the newsgroups. Judging by
>>his other replies though I view his action as a badge of honour and worthy of
>>distinction.
>
> Why how precious. Plonked.
I've now been plonked by two people in this newsgroup. Whoohooo!!
Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/ >> Stay informed about: Multiple tables refer to one -To use foreign keys or not? |
|
| Back to top |
|
 |  |
External

Since: Jan 11, 2008 Posts: 440
|
(Msg. 21) Posted: Mon Jun 02, 2008 7:18 pm
Post subject: Re: Multiple tables refer to one -To use foreign keys or not? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"Adriano Varoli Piazza" wrote in message
> As one of my first encounters with SQL (The RDBMS used is MySQL 5.1),
> my colleague and I have designed the following (it's a part of a
> catalog system for a museum):
> We have an "attachments" table, which can refer to "works_of_art",
> "people", "reproductions" (Let's say, more than three tables). So a
> work of art can have attachments, a person can have a different
> attachment, etc.
>
> To be able to relate each object to its eventual attachments, one
> solution I imagined is to put N foreign keys from each of the tables
> referred in attachments (if my use of the verb refer is incorrect,
> please do point it out). Let's say that, for now, there are no fields
> exclusive to any of the referred tables, so creating different
> attachment tables is not the best obvious choice.
>
> The alternative solution we came up with was to use two fields in
> "attachments" to identify the relations: one with the id of the
> referred table, and one with the "type". So 'works of art' would be 0,
> 'people' would be 1... The reasoning behind the decision was that my
> colleague felt that too many fields would remain empty with the first
> solution, and that adding a new type of "attachee" was simpler/more
> efficient than adding a new foreign key.
>
Don't do this. It's been tried thousands of times. It nearly always leads
to chaos.
The general principle is: don't put data and metadata side by side in the
same table.
I have violated this principle in my own private tools, but never in work
to be used by others. >> Stay informed about: Multiple tables refer to one -To use foreign keys or not? |
|
| Back to top |
|
 |  |
External

Since: Aug 11, 2008 Posts: 2
|
(Msg. 22) Posted: Tue Aug 19, 2008 10:43 pm
Post subject: Re: Multiple tables refer to one -To use foreign keys or not? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
If I understand your problem correctly then the constraints that you desire
are called "distributed foreign keys" and they're described at
http://www.dcs.warwick.ac.uk/~hugh/TTM/Missing-info-without-nulls.pdf The
snag is that no DBMS on the market today supports them in a simple
declarative way like they do with the SQL "FOREIGN KEY" syntax. You can
implement them using triggers, which is described in:
Koppelaars, T. and de Haan, L. Applied Mathematics for Database
Professionals. Apress. 2007.
Regards,
Adrian
"Adriano Varoli Piazza" wrote in message
> As one of my first encounters with SQL (The RDBMS used is MySQL 5.1),
> my colleague and I have designed the following (it's a part of a
> catalog system for a museum):
> We have an "attachments" table, which can refer to "works_of_art",
> "people", "reproductions" (Let's say, more than three tables). So a
> work of art can have attachments, a person can have a different
> attachment, etc.
>
> To be able to relate each object to its eventual attachments, one
> solution I imagined is to put N foreign keys from each of the tables
> referred in attachments (if my use of the verb refer is incorrect,
> please do point it out). Let's say that, for now, there are no fields
> exclusive to any of the referred tables, so creating different
> attachment tables is not the best obvious choice.
>
> The alternative solution we came up with was to use two fields in
> "attachments" to identify the relations: one with the id of the
> referred table, and one with the "type". So 'works of art' would be 0,
> 'people' would be 1... The reasoning behind the decision was that my
> colleague felt that too many fields would remain empty with the first
> solution, and that adding a new type of "attachee" was simpler/more
> efficient than adding a new foreign key.
>
> This solution doesn't strike me as the best. We want to use cakephp to
> build the app that will use the database, and while this solution
> would eventually work with some manual labour, I feel it grates
> against it when the rest of the design does not. Since my knowledge of
> SQL is tenuous at best, I wanted to listen to some informed opinions
> about this before arguing again.
>
> By all means, if this is a WTF, point it out, the reason, and possibly
> an alternative.
>
> Saludos,
> Adriano >> Stay informed about: Multiple tables refer to one -To use foreign keys or not? |
|
| Back to top |
|
 |  |
External

Since: Jan 17, 2008 Posts: 164
|
(Msg. 23) Posted: Wed Aug 20, 2008 5:12 pm
Post subject: Re: Multiple tables refer to one -To use foreign keys or not? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Jun 2, 2:01 am, "Tony Toews [MVP]" wrote:
> Gene Wirchenko wrote:
> >>Bob has marked my postings to be ignored so he won't read my reply. As far as I
> >>know he is the only person who has ever kill filed me in the newsgroups. Judging by
> >>his other replies though I view his action as a badge of honour and worthy of
> >>distinction.
>
> > Why how precious. Plonked.
>
> I've now been plonked by two people in this newsgroup. Whoohooo!!
I gotta be honest, I couldn't see the relevance of you response to the
OP's question. Roy's and Adrian's responses were good pointers, while
the general warning away from EAV by everyone else was also apt. I'm
not sure how your personal anecdote contributed to his trying to
reference multiple relations from the same foreign key.
>
> Tony
> --
> Tony Toews, Microsoft Access MVP
> Please respond only in the newsgroups so that others can
> read the entire thread of messages.
> Microsoft Access Links, Hints, Tips & Accounting Systems athttp://www.granite.ab.ca/accsmstr.htm
> Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/
To the OP - have you considered just using different tables for the
attachments? Sure attachments are all of the same type but relations
don't collectivize objects (a common misconception that has to be
shaken off when moving from OO to RM). Relations collectivize
propositions of a common form - and yours seem to be different.
Regards, J. >> Stay informed about: Multiple tables refer to one -To use foreign keys or not? |
|
| Back to top |
|
 |  |
| Related Topics: | Foreign keys - Always a physical issue. Never a theory issue.Agree? Evan
semantics of foreign keys: domain specific inequality? - I'm trying to figure out how to deal with the relative importance of tables involved in a foreign-key relationship. My actual problem is one of generating HTML pages directly from database schemas (think of ruby-on-rails, django, etc.), and doing it in ...
Multiple keys and transition constraints - Given a relation schema R {A, B, C}, where A and B are each candidate keys. If the current extension is r {{A:1, B:9, C:3} {A:2, B:8, C:4}} and the proposed extension is r' {{A:1, B:8, C:4} {A:2, B:9, C:3}} is only A different? Or are both ...
Multiple-Attribute Keys and 1NF - I am still fighting with the theoretical underpinning for 1NF. As such, any comments would be greatfully accepted. The reason for my concern is that there /seems/ instances where 1NF is insufficient. An example occurred to me while I was wiring up a..
Multiple Parent Tables (or Multiple Inheritence, or - Hi, It seems to be a common enough problem, but it doesn't seem to ever be properly addressed in data modelling books, and from reading on the web its clear that other people have had this problem as well as had multiple solutions presented, but its.. |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|