kaplanyo Posted March 7, 2009 Share Posted March 7, 2009 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 Link to comment https://forums.phpfreaks.com/topic/148374-beginner-question-about-primary-and-foreign-keys/ Share on other sites More sharing options...
fenway Posted March 9, 2009 Share Posted March 9, 2009 It's not great... duplicate issues, typos, etc... why bother? Link to comment https://forums.phpfreaks.com/topic/148374-beginner-question-about-primary-and-foreign-keys/#findComment-780144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.