nec9716 Posted April 9, 2008 Share Posted April 9, 2008 I want to create relation between table but I have an issue. not sure if I write the line properly? alter table `matnphil_f1`.`pick` add constraint `FK_pick` FOREIGN KEY (`id`) REFERENCES `user` (`userid`) do the table need to be emty to do that? presently I have data in all table ..... thank you Quote Link to comment https://forums.phpfreaks.com/topic/100322-relationship-between-table/ Share on other sites More sharing options...
drewbee Posted April 9, 2008 Share Posted April 9, 2008 The constraint will not add to the table if your current data violates the constraint. Quote Link to comment https://forums.phpfreaks.com/topic/100322-relationship-between-table/#findComment-513035 Share on other sites More sharing options...
nec9716 Posted April 9, 2008 Author Share Posted April 9, 2008 ok i get that working now ...table need to be empty ... now my next question is : is it just the primary key who can be put in relationship between tables? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/100322-relationship-between-table/#findComment-513259 Share on other sites More sharing options...
drewbee Posted April 11, 2008 Share Posted April 11, 2008 There are different types of constraints and relationships, but I am not sure I understand why you would want to use a non-pk in one table as a fk in another? A relationship can be between anything; but it just makes sense to use the primary key. Quote Link to comment https://forums.phpfreaks.com/topic/100322-relationship-between-table/#findComment-515088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.