Jump to content

Foreign Keys


Recommended Posts

I have a series of tables in a database, each one pertaining to a classified ad category. I need another table that groups all of their id's together in one place. Do I set the foreign keys in the new table to reference the others, or do I set the fk's in each table to reference the new one?

Link to comment
Share on other sites

Like this?

Ad Categories

===================================================

id | name

1  | Auto

2  | Home

3  | Pets

 

Ads

===================================================

id | cat_id | desc

1  | 3      | 2 yr. old hound.

2  | 1      | 1990 VW Bug.

3  | 2      | 4 bedroom somethingorother.

In this case cat_id is the foreign key, which references Ad Categories' id.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.