Page 1 of 1

KEY `cat_parent_id` (`cat_parent_id`),

Posted: Sat Mar 20, 2010 1:13 pm
by mannyee
hi guys!!

while going through a tutorial, i found the following query used in it:
CREATE TABLE IF NOT EXISTS `tbl_category` (
`cat_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`cat_parent_id` int(11) NOT NULL DEFAULT '0',
`cat_name` varchar(50) NOT NULL DEFAULT '',
`cat_description` varchar(200) NOT NULL DEFAULT '',
`cat_image` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`cat_id`),
KEY `cat_parent_id` (`cat_parent_id`),
KEY `cat_name` (`cat_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

and here i am confused about the use of
KEY `cat_parent_id` (`cat_parent_id`),
KEY `cat_name` (`cat_name`)
why are they used?

Re: KEY `cat_parent_id` (`cat_parent_id`),

Posted: Sat Mar 20, 2010 1:28 pm
by John Cartwright
KEY's are used to index the particular column to allow the quick retrieval of that particular data. However, they take up more memory so it's important to only use keys on columns that are used store the relationships (foreign keys) between tables, and highly searched columns.

See http://www.google.ca/search?q=database+ ... =firefox-a for more info.