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  dBforums > General > Database Concepts & Design > Foreign Key problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-09, 03:55
bubboo bubboo is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
Question Foreign Key problem

I am building a database and have hit a problem while assigning foreign keys.

Assume I have a table for photo albums as follows:

Code:
albums( aid integer,
	name varchar(100),
	description varchar(1000),
	locationid integer,
	type varchar(10),
)
I also have tables for user, group, events (like facebook). Each of these tables has a PK (uid, gid, eid) which i want to use as a FK in the albums table in the attribute locationid where the attribute type is the name of the table. This lets me have an album for photos, users or groups. The problem is that I am unable to set locationid to be a FK to uid & pid & gid at the same time.

If I don't set locationid as a FK then it all works, but that is bad design.
Any advice on how the change my design?
Reply With Quote
  #2 (permalink)  
Old 04-17-09, 04:02
bubboo bubboo is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
worked it out...
i just need to add a column in user, group and events tables which is a FK to the aid of albums. then i can remove the location id
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On