Solved

One foreign key referencing primary key in multiple tables

Posted on 2011-03-22
4
570 Views
Last Modified: 2012-06-22
Assignment table(assignmentid

pk,title,etc.,assignmenttype(1=forum,2=journal,etc),refid (id of a

forumthread,or id of a journal)

_______________________

forum table(threadid pk,threadtitle,graded y/n,etc.

________________

journal table(journalid,journaltitle,gradedy/n.etc.)

________________

is it ok to use refid as a foriegn key referencing forumid in fourm

table if the assignment type is forum

and refid is a foreign key referencing journalid in journal table if

assignment type is journal

how this can be accomplised in the best way to improve performance

I thought of doing the following

adding the following two tables journalassign(journalid,assignmentid)

and forumassign(forumid, assignm)

___________________________
I thought of another alternative please let me know the best way to go

for it

Assignment table(assignmentid

pk,title,etc.,assignmenttype(1=forum,2=journal,etc),refid (id of a

forumthread,or id of a journal)

foreign key1 is (assignmenttype+refid) referencing threadi+type in forum

table
foreign key2 is (assignmenttype+refid) referencing journalid+type in

journal table

forum table((threadid +Type=1) pk,threadtitle,graded y/n,etc.
and

________________

journal table((journalid+type=2)pk,journaltitle,gradedy/n.etc.)

________________
but I have similar situations in other tables

example:

lessontools(lessonid +  toolid pk, tooltype (1=dropbox,2=,etc.)

dropbox(dropboxid, etc)

___________________
Please see attached diagram and give me your opinion

thanks Data diagram
0
Comment
Question by:sohairzaki2005
  • 2
4 Comments
 
LVL 37

Expert Comment

by:ValentinoV
ID: 35196283
In your Assignment table I would create two foreign keys: ForumID to refer to your Forum table and JournalID to refer to yourJournal table.  When AssignmentType = 1 then ForumID should be filled in.  And when type=2 then JournalID should be filled in.

However, I notice that your primary keys are sometimes made up of several fields, for instance your Journal table's PK is JournalID and ToolType.  That seems a bit weird.  Isn't your JournalID unique across all records?
0
 

Author Comment

by:sohairzaki2005
ID: 35199122
I do not think this is a good idea.
Thanks
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 35205547
Would you mind sharing why you think that my suggestion is not a good idea?

Another option that would be acceptable but less interesting that my earlier suggestion, in my opinion, is that you create two tabes: JournalAssignment and ForumAssignment.

As for LessonTools: why would you store ToolType there?  It seems to me that ToolType is an attribute of "Tool" and thus belongs in the Tool table (which is referred to through ToolID)?
0
 
LVL 5

Accepted Solution

by:
bitref earned 500 total points
ID: 35207034
You may create a new table as an intermadiate link in which you store the many-to-many relationship foreign key data.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now