nomadsoul Posted June 11, 2011 Share Posted June 11, 2011 I'm doing a project from an ecommerce book and it says "the non_coffee_products table has a many to one relationship with the non_coffee_categories table" I have listed them both below but I see no fk-references syntax. I see absolutely no connection between these two tables. Does the Key Index link these tables? I guess I need a tutorial on Indexes CREATE TABLE `non_coffee_products` ( `id` mediumint( unsigned NOT NULL AUTO_INCREMENT, `non_coffee_category_id` tinyint(3) unsigned NOT NULL, `name` varchar(60) NOT NULL, `description` tinytext, `image` varchar(45) NOT NULL, `price` decimal(5,2) unsigned NOT NULL, `stock` mediumint( unsigned NOT NULL DEFAULT '0', `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `non_coffee_category_id` (`non_coffee_category_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE `non_coffee_categories` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `category` varchar(40) NOT NULL, `description` tinytext NOT NULL, `image` varchar(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `category` (`category`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Quote Link to comment https://forums.phpfreaks.com/topic/239031-question-about-foreign-key-index-in-mysql/ Share on other sites More sharing options...
Muddy_Funster Posted June 13, 2011 Share Posted June 13, 2011 It depends - Relationships can be generated on the fly within queries (using RIGHT or LEFT JOIN), they don't need to be declaired through key indexes. Quote Link to comment https://forums.phpfreaks.com/topic/239031-question-about-foreign-key-index-in-mysql/#findComment-1228970 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.