Jump to content

Question about Foreign Key / Index in MySQL


nomadsoul

Recommended Posts

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.