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
https://forums.phpfreaks.com/topic/61889-foreign-keys/#findComment-308126
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
https://forums.phpfreaks.com/topic/61889-foreign-keys/#findComment-308183
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.