Jump to content

Recommended Posts

I would like to know if it's a bad idea to not use the primary key from one table as the foreign key in another. What if I use a different field as the foreign key.

 

I have a Project List and a Project Image Library. I want to associate a field in the library with one of the projects. I started by using the PK of the Projects as the FK of a library image, but I'd rather use a name instead of the id, it makes more sense for listing and selection for the user. I've got it working without using the PK and using the name field, but I'm just wondering if that approach is ok.

 

Maybe I can explain more... if I have a table called 'projects' with a field called 'project_id' (the primary key) and 'name'... is it a bad idea to use 'name' as my foreign key in another table, project_images - that table has 'item_id' (the primary key) and 'project_name'. I want to use 'name' from 'projects' and put it in 'project_name' in the 'project_images'.

 

Thanks. Any advice would be really great. I can also post a link or take some screen shots to show what I mean.

Dave

 

I'm using:

MySQL client version: 5.0.22

Used PHP extensions: mysql

 

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.