Madatan Posted March 4, 2006 Share Posted March 4, 2006 Okey, so I tried to create a Foreign Key in MySQL by using the following commands:FOREIGN KEY(keyname) REFERENCES tablename(keyname)The table was create but foreign keys didn't work. Is foreign keys even supported by mysql and if it is how do I make one? Link to comment https://forums.phpfreaks.com/topic/4077-mysql-foreign-key/ Share on other sites More sharing options...
wickning1 Posted March 4, 2006 Share Posted March 4, 2006 I believe foreign keys are supported if you create an InnoDB table, but MyISAM does not support them. You can read about the various differences between InnoDB and MyISAM in the mysql documentation. Link to comment https://forums.phpfreaks.com/topic/4077-mysql-foreign-key/#findComment-14164 Share on other sites More sharing options...
Madatan Posted March 8, 2006 Author Share Posted March 8, 2006 [!--quoteo(post=351595:date=Mar 4 2006, 10:13 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 4 2006, 10:13 AM) [snapback]351595[/snapback][/div][div class=\'quotemain\'][!--quotec--]I believe foreign keys are supported if you create an InnoDB table, but MyISAM does not support them. You can read about the various differences between InnoDB and MyISAM in the mysql documentation.[/quote]I see, good to know. That helps alot, can I combine MyISAM and InnoDB or do I have to make all the connected tables of the same type? For example, can I have a foreign key in a InnoDB table that references to a MyISAM table? Link to comment https://forums.phpfreaks.com/topic/4077-mysql-foreign-key/#findComment-15448 Share on other sites More sharing options...
fenway Posted March 8, 2006 Share Posted March 8, 2006 Unfortunately not -- and that causes all sorts of weird errors to when trying to enforce referential integrity. Link to comment https://forums.phpfreaks.com/topic/4077-mysql-foreign-key/#findComment-15487 Share on other sites More sharing options...
Madatan Posted March 9, 2006 Author Share Posted March 9, 2006 I see, thanks for that info. Link to comment https://forums.phpfreaks.com/topic/4077-mysql-foreign-key/#findComment-15731 Share on other sites More sharing options...
lpxxfaintxx Posted March 9, 2006 Share Posted March 9, 2006 There is an alternative way, however. Try this: [a href=\"http://mysqld.active-venture.com/example-Foreign_keys.html\" target=\"_blank\"]http://mysqld.active-venture.com/example-Foreign_keys.html[/a] Link to comment https://forums.phpfreaks.com/topic/4077-mysql-foreign-key/#findComment-15736 Share on other sites More sharing options...
fenway Posted March 9, 2006 Share Posted March 9, 2006 That "alternative" is NOT referential integrity -- it's just a JOIN statement. That is, using foreign keys is not equivalent in any way, shape or form to having referential integrity. We all use foreign keys all the time. Link to comment https://forums.phpfreaks.com/topic/4077-mysql-foreign-key/#findComment-15777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.