This article the 3rd installment in of a series titled 'How I build an application'. You can find the other two installments and subsection here.
I mentioned last time that I would discuss why I choose certain data types for certain fields.
Recipe Ingredient Table
--
-- Table structure for table `recipe_ingredient`
--
CREATE TABLE IF NOT EXISTS `recipe_ingredient` (
`recipe_ingredient_id` int(10) unsigned NOT NULL auto_increment,
`recipe_id` int(10) unsigned NOT NULL default '0',
`unit_id` int(10) unsigned NOT NULL default '0',
`ingredient_id` int(10) unsigned NOT NULL default '0',
`unit_amount` tinyint(3) NOT NULL default '0',
PRIMARY KEY (`recipe_ingredient_id`),
KEY `IDX_recipe_ingredient_recipe_id` (`recipe_id`),
KEY `IDX_recipe_ingredient_unit_id` (`unit_id`),
KEY `IDX_recipe_ingredient_ingredient_id` (`ingredient_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
This table is one that ties a lot together, so we'll start here. This table contains a primary key and three foreign keys. I try to always construct my integer keys using a display length of 10, marking them unsigned with a default of zero. Whether a field is marked at 'NULL' or 'NOT NULL' depends on the design. read more »